help with popup code

Discussion in 'JavaScript' started by DjZoC, May 29, 2010.

  1. #1
    hello there, this is the code

       var puShown = false;
    
       function doOpen(url)
       {
               if ( puShown == true )
               {
                       return true;
               }
    
               win = window.open(url, 'wmPu', 'toolbar,status,resizable,scrollbars,menubar,location,height=680,width=790');
               if ( win )
               {
                       win.blur();
                       puShown = true;
               }
               return win;
       }
       
       
       function setCookie(name, value, time)
       {
           var expires = new Date();
           
           expires.setTime( expires.getTime() + time );
           
           document.cookie = name + '=' + value + '; expires=' + expires.toGMTString();
       }
       
       
       function getCookie(name) {
           var cookies = document.cookie.toString().split('; ');
           var cookie, c_name, c_value;
           
           for (var n=0; n<cookies.length; n++) {
               cookie  = cookies[n].split('=');
               c_name  = cookie[0];
               c_value = cookie[1];
               
               if ( c_name == name ) {
                   return c_value;
               }
           }
           
           return null;
       }
    
    
       function initPu()
       {
               if ( document.attachEvent )
               {
                       document.attachEvent( 'onclick', checkTarget );
               }
               else if ( document.addEventListener )
               {
                       document.addEventListener( 'click', checkTarget, false );
               }
       }
       
       
       function checkTarget(e)
       {
           if ( !getCookie('popundr') ) {
               var e = e || window.event;
               var win = doOpen('http://www.google.com');
               
               setCookie('popundr', 1, 5*60*1000);
           }
       }
    
       initPu();
    Code (markup):
    how i can make first time to open www.google.com and after 5 minutes (if the person stay 5 minutes on website) to open www.yahoo.com and after www.yahoo.com to stop for 24 hours (dont open anymore website for 24 hours) ...

    hope someone can help me with this ... thanks
     
    DjZoC, May 29, 2010 IP
  2. Qc4

    Qc4 Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm assuming you want the second window to open automatically? If so, after this line:

    var win = doOpen('http://www.google.com');
    Code (markup):
    add:

    var win2 = window.setTimeout(doOpen, 300000, 'http://www.yahoo.com');
    Code (markup):
     
    Qc4, May 29, 2010 IP
  3. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
       var puShown = false;
    
       function doOpen(url)
       {
               if ( puShown == true )
               {
                       return true;
               }
    
               win = window.open(url, 'wmPu', 'toolbar,status,resizable,scrollbars,menubar,location,height=680,width=790');
               if ( win )
               {
                       win.blur();
                       puShown = true;
               }
               return win;
       }
       
       
       function setCookie(name, value, time)
       {
           var expires = new Date();
           
           expires.setTime( expires.getTime() + time );
           
           document.cookie = name + '=' + value + '; expires=' + expires.toGMTString();
       }
       
       
       function getCookie(name) {
           var cookies = document.cookie.toString().split('; ');
           var cookie, c_name, c_value;
           
           for (var n=0; n<cookies.length; n++) {
               cookie  = cookies[n].split('=');
               c_name  = cookie[0];
               c_value = cookie[1];
               
               if ( c_name == name ) {
                   return c_value;
               }
           }
           
           return null;
       }
    
    
       function initPu()
       {
               if ( document.attachEvent )
               {
                       document.attachEvent( 'onclick', checkTarget );
               }
               else if ( document.addEventListener )
               {
                       document.addEventListener( 'click', checkTarget, false );
               }
       }
       
       
       function checkTarget(e)
       {
           if ( !getCookie('popundr') ) {
               var e = e || window.event;
               var win = doOpen('http://www.yahoo.com');
               var win2 = window.setTimeout(doOpen, 300000, 'http://www.google.com');
               
               setCookie('popundr', 1, 24*60*60*1000);
           }
       }
    
       initPu();";
    Code (markup):
    i try like this but www.yahoo.com is open but after 5 minutes is not open www.google.com
     
    DjZoC, May 29, 2010 IP
  4. Qc4

    Qc4 Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh, looks like IE doesn't allow extra parameters to be passed to window.setTimeout(). Instead, change the line you just added to this:

    var win2 = window.setTimeout("doOpenDelay()", 300000);
    Code (markup):
    Then, add this function above the checkTarget() function:

    function doOpenDelay()
    {
      return doOpen('http://www.google.com');
    }
    Code (markup):
     
    Qc4, May 30, 2010 IP