Web Analytics Made Easy -
StatCounter Need a PopUp AND a PopUnder for same main window - CodingForum

Announcement

Collapse
No announcement yet.

Need a PopUp AND a PopUnder for same main window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need a PopUp AND a PopUnder for same main window

    Hi all, I am very new at this - and have found code everywhere for pop ups and popunders, but I need both in the same place.

    So - I am on a main page with a link. If the user clicks the link they get a popup window (it is a specific url). When the user exits out of the popup, I want the popunder to go under the main window they were looking at (not the popup window)

    If I am in my main window, I have an href link to click for the popup.html window. This works fine, and I tried to put the code into the popup.html to load the popunder upon exit. What a disaster. It loads on TOP of the main window because of course it is trying to popunder the popup.

    Focus is never returned to the main window.

    Is there any one that has any ideas on how to do this? I have looked at it for days and cannot figure it out - but like I said, I am very, very new at javascript.

    Any help is truly appreciated.

  • #2
    Huh???

    Can't you just set focus back to the main window after popping up the popunder???

    That is:
    Code:
    <body onunload="window.open('spam.html','spam');window.focus();">
    Never tried it, but don't see why it wouldn't work. Be prepared for you users to hate you for this, of course.

    *******************

    EDIT: Just tried it. Worked as advertised in MSIE. Fails miserably with FireFox. So another of those admittedly relatively rare case where FireFox (Mozilla) messes us over.

    I even tried putting something like
    Code:
    <body onload="opener.document.body.focus( );">
    into the popup. Again, it would work with MSIE but not with FF.

    Go figure.

    *****************

    EDIT MORE: AHA! Got it to work!

    In the POPUP page, just do
    Code:
    <body onload="window.blur( );">
    and that works in both MSIE and FF!!

    Hacky, but who cares!

    In FF, it just puts the window behind the opener. In MSIE it puts the window at the very bottom of ALL open windows. But what do you want for free?
    Last edited by Old Pedant; Apr 6, 2009, 11:18 PM.
    Be yourself. No one else is as qualified.

    Comment


    • #3
      Just to remind you what Old Pedant said. Popunders are guaranteed to annoy your users.

      John

      Comment


      • #4
        you can get the popup to come to the front with focus and the popunder gets set to blur.

        here's a script for multiple timed popunders
        put both of these files in the same folder. the smaller file below calls this page, which has the popunders
        hidden_popup.html

        right now I set the times at 5 15 30 and 45 seconds after load, but you can adjust it so they run at different times
        Code:
        <html>
        <head>
        <script language=javascript>
        
        // ***********************************************
        // AUTHOR: WWW.CGISCRIPT.NET, LLC
        // URL: http://www.cgiscript.net
        // Use the script, just leave this message intact.
        // Download your FREE CGI/Perl Scripts today!
        // ( http://www.cgiscript.net/scripts.htm )
        // ***********************************************
        
        //### array setup - leave this alone
        
        var pURL = new Array();
        var pName = new Array();
        var pPos = new Array();
        var pDelay = new Array();
        var pHeight = new Array();
        var pWidth = new Array();
        
        //### configure your popups here ###
        
        //### URLs of the Popup Windows ###
        //### you can add as many as you want ###
        //### start with [0] and increment up by one ([1], [2], etc...) ###
        
        pURL[0] = "";
        pURL[1] = "";
        pURL[2] = "";
        pURL[3] = "";
        
        //### Name of the Popup Windows. If you choose the same name, it will load in the same window ###
        //### If you add URLs above you must add corresponding name below ###
        pName[0] = "pop1";
        pName[1] = "pop2";
        pName[2] = "pop3";
        pName[3] = "pop4";
        
        //### Height of popup ###
        //### If you add URLs above you must add corresponding height below ###
        pHeight[0] = "200";
        pHeight[1] = "500";
        pHeight[2] = "800";
        pHeight[3] = "300";
        
        //### Width of popup ####
        //### If you add URLs above you must add corresponding width below ###
        pWidth[0] = "600";
        pWidth[1] = "500";
        pWidth[2] = "700";
        pWidth[3] = "300";
        
        //###position of popup. Options: center, random, base (0,0) ###
        //### If you add URLs above you must add corresponding position below ###
        pPos[0] = "center"
        pPos[1] = "random"
        pPos[2] = "random"
        pPos[3] = "base"
        
        //### seconds that will lapse before window pops up ###
        //### If you add URLs above you must add corresponding delay below ###
        pDelay[0] = "5";
        pDelay[1] = "15";
        pDelay[2] = "30";
        pDelay[3] = "45";
        
        //<--- don't edit any code below --->//
        
        var win=null;
        function OpenWindow(url,id,w,h,scroll,pos,t,l){
        if(pos=="random"){
          Left=Math.floor(Math.random()*(screen.width-w));
          Top=Math.floor(Math.random()*((screen.height-h)-75));
          }
        if(pos=="center"){
          Left=(screen.width-w)/2;
          Top=(screen.height-h)/2;
          }
        if(pos=="base"){
          Left=0;
          Top=0;
          }
        if(pos=="absolute"){
          Left=t;
          Top=l;
          }
        set='width='+w+',height='+h+',top='+Top+',left='+Left+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
        mywin=window.open(url,id,set);
        mywin.focus();mywin.blur();
        }
        
        for(var npop in pURL){
        var st= "OpenWindow('"+pURL[npop]+"','"+pName[npop]+"',"+pWidth[npop]+","+pHeight[npop]+",'yes','"+pPos[npop]+"',0,0)";
        setTimeout(st,pDelay[npop]*1000);
        }
        
        </script>
        </head>
        <body>
        
        </body>
        </html>
        this is the page you call to begin the process. It makes a tiny little window and blurs itself also. Be sure to set the correct address for your hidden.html page in this script below.
        spawner.html
        Code:
        <html>
        <head>
        <SCRIPT LANGUAGE="JAVASCRIPT" >
        
        // ***********************************************
        // AUTHOR: WWW.CGISCRIPT.NET, LLC
        // URL: http://www.cgiscript.net
        // Use the script, just leave this message intact.
        // Download your FREE CGI/Perl Scripts today!
        // ( http://www.cgiscript.net/scripts.htm )
        // ***********************************************
        
        function openSpawner(url,name) {
        window.open('hidden_popup.html','popper','width=10,height=10,top=15000,left=15000,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
        }
        
        </SCRIPT>
        </head>
        <body onLoad="openSpawner();self.blur()">
        
        </body>
        </html>
        Last edited by TinyScript; Apr 7, 2009, 11:46 AM.

        Comment


        • #5
          Originally posted by Actinia View Post
          Just to remind you what Old Pedant said. Popunders are guaranteed to annoy your users.

          John
          the key is to time a popunder with a link click so they don't notice where it came from. The user might think it was the linked page that threw up the ad.
          Also a popunder onload is standard too.

          Comment


          • #6
            Originally posted by Old Pedant View Post
            Huh???

            Can't you just set focus back to the main window after popping up the popunder???

            That is:
            Code:
            <body onunload="window.open('spam.html','spam');window.focus();">
            Never tried it, but don't see why it wouldn't work. Be prepared for you users to hate you for this, of course.

            *******************

            EDIT: Just tried it. Worked as advertised in MSIE. Fails miserably with FireFox. So another of those admittedly relatively rare case where FireFox (Mozilla) messes us over.

            I even tried putting something like
            Code:
            <body onload="opener.document.body.focus( );">
            into the popup. Again, it would work with MSIE but not with FF.

            Go figure.

            *****************

            EDIT MORE: AHA! Got it to work!

            In the POPUP page, just do
            Code:
            <body onload="window.blur( );">
            and that works in both MSIE and FF!!

            Hacky, but who cares!

            In FF, it just puts the window behind the opener. In MSIE it puts the window at the very bottom of ALL open windows. But what do you want for free?
            Here is what i am doing - perhaps you can tell me where I am going wrong... I tried what you said on your last edit and it didn't work - perhaps I am putting it in the wrong place..

            I have two html files. (HTML_PAGE_1.html and Popup.html)

            HTML_PAGE_1. html has the following javascript in it to pull up the popup.html page

            <body>
            <SCRIPT TYPE="text/javascript">
            <!--
            function popup(mylink, windowname)
            {
            if (! window.focus)return true;
            var href;
            if (typeof(mylink) == 'string')
            href=mylink;
            else
            href=mylink.href;
            window.open(href, windowname, 'width=310,height=440,scrollbars=no, screenx=400, screeny=200');
            return false;
            }
            //-->
            </SCRIPT>
            <A HREF="popoup.html" onClick="return popup(this, 'popup window')">Click here</A>
            </body>



            Popup.html has the following code (you can see where I added your suggestion)

            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Untitled Document</title>
            <script language="javascript">


            var exit=true;
            function exitwindow()
            {
            var url = 'http://www.randomsite.com';
            var win = 'toolbar=0,directories=0,menubar=0,scrollbars=0,resizable=0';
            if (exit)
            open(url,'WindowName',win); }


            </script>


            </head>

            <body onUnload="exitwindow(); window.blur();">

            <img src="image.gif" width="290" height="420"/>

            </body>



            What I need is for the www.randomsite.com to go behind the HTML_PAGE_1.html when popup.html is exited.

            Does this make sense at all? I appreciate your input so far, and it sounds like you may be able to tell me whare I am going wrong here... thank you so much for any time you have spent on this. I really appreciate it...

            Comment


            • #7
              No no...you would have to be able to put the "window.blur()" *into* the code for the www.randomsite.com page!

              Since you don't "own" that page, I don't see how you can do that.

              Maybe the best you could do would be to link to a page OF YOUR OWN that is actually just a <FRAMESET> with a single <FRAME> that contains the www.randomsite.com page. It could then do the blur() of itself. Might work okay because most commercial sites have code in them to hoist themselves *out* of a <FRAME>, so after the <FRAMESET> shoves the window under, the contents of the <FRAME> pop themselves out of the frame.

              BUT...

              But, any site that does that is *also* liable to call window.focus( ) to bring themselves to the front! Thus defeating your whole effort!

              But you could try it.
              Be yourself. No one else is as qualified.

              Comment

              Working...
              X