1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Free Javascript Popunder which works!

Discussion in 'HTML & JavaScript' started by garundang, Jun 1, 2011.

  1. garundang

    garundang Registered Member

    Joined:
    Apr 2, 2011
    Messages:
    82
    Likes Received:
    100
    Location:
    Offshore Hell
    Here is the code that I had to code so it pops under in the background for all browsers and popup is centered. I think only Opera opens it in a new tab.

    It is based on another free available popunder code.

    P.S. Code works when user clicks on the page or body background. This way blockers can?t stop it.


    Code:
    <script>
    var puShown = false;
    var PopWidth = 1370;
    var PopHeight = 800;
    var PopFocus = 0;
    var _Top = null;
    
    function GetWindowHeight() {
    var myHeight = 0;
    if( typeof( _Top.window.innerHeight ) == 'number' ) {
    myHeight = _Top.window.innerHeight;
    } else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
    myHeight = _Top.document.documentElement.clientHeight;
    } else if( _Top.document.body && _Top.document.body.clientHeight ) {
    myHeight = _Top.document.body.clientHeight;
    }
    return myHeight;
    }
    
    function GetWindowWidth() {
    var myWidth = 0;
    if( typeof( _Top.window.innerWidth ) == 'number' ) {
    myWidth = _Top.window.innerWidth;
    } else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
    myWidth = _Top.document.documentElement.clientWidth;
    } else if( _Top.document.body && _Top.document.body.clientWidth ) {
    myWidth = _Top.document.body.clientWidth;
    }
    return myWidth;
    }
    
    function GetWindowTop() {
    return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
    }
    
    function GetWindowLeft() {
    return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
    }
    
    function doOpen(url)
    {
    var popURL = "about:blank"
    var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
    var pxLeft = 0;
    var pxTop = 0;
    pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
    pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
    
    if ( puShown == true )
    {
    return true;
    }
    
    var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
    
    if (PopWin)
    {
    puShown = true;
    
    if (PopFocus == 0)
    {
    PopWin.blur();
    
    if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
    {
    _Top.window.blur();
    _Top.window.focus();
    }
    }
    
    PopWin.Init = function(e) {
    
    with (e) {
    
    Params = e.Params;
    Main = function(){
    
    if (typeof window.mozPaintCount != "undefined") {
    var x = window.open("about:blank");
    x.close();
    
    }
    
    var popURL = Params.PopURL;
    
    try { opener.window.focus(); }
    catch (err) { }
    
    window.location = popURL;
    }
    
    Main();
    }
    };
    
    PopWin.Params = {
    PopURL: url
    }
    
    PopWin.Init(PopWin);
    }
    
    return PopWin;
    }
    
    function setCookie(name, value, time)
    {
    var expires = new Date();
    
    expires.setTime( expires.getTime() + time );
    
    document.cookie = name + '=' + value + '; path=/;' + '; 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()
    {
    
    _Top = self;
    
    if (top != self)
    {
    try
    {
    if (top.document.location.toString())
    _Top = top;
    }
    catch(err) { }
    }
    
    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('YOUR URL HERE');
    
    setCookie('popundr', 1, 24*60*60*1000);
    }
    }
    
    initPu();
    </script>
     
    • Thanks Thanks x 25
  2. marysmith1243

    marysmith1243 Registered Member

    Joined:
    May 27, 2011
    Messages:
    66
    Likes Received:
    2
    Nice coding. hope it will be effective.
     
  3. garundang

    garundang Registered Member

    Joined:
    Apr 2, 2011
    Messages:
    82
    Likes Received:
    100
    Location:
    Offshore Hell
    im using it to my affliate site.
     
  4. waynem80

    waynem80 Newbie

    Joined:
    Jun 12, 2011
    Messages:
    1
    Likes Received:
    0
    How do you make it resize to full window. I don't know javascript.
     
  5. Kaistar

    Kaistar Power Member

    Joined:
    Jan 9, 2010
    Messages:
    562
    Likes Received:
    333
    Thanks for this, I gave up on finding one that worked ok ages ago.
    This one works perfectly.

    Is there any way though to save it to a .js file and just have one line of code on the page to call it?

    Sorry, not too familiar with JS at all.

    I've tried creating a pop.js file with the code in it and uploading it to root and then placing this code in <head> section but it doesn't work.

    Code:
    <SCRIPT LANGUAGE="JavaScript" SRC="myJSfile.js">
    </SCRIPT>
    Any info would be appreciated,
    Thanks,
    Kai.
     
  6. projectx

    projectx Power Member

    Joined:
    Dec 4, 2006
    Messages:
    644
    Likes Received:
    721
    thanks, was looking for a script that really worked. Test it 2 minutes ago and work perfect.
     
  7. andy2009

    andy2009 Junior Member

    Joined:
    Apr 18, 2009
    Messages:
    164
    Likes Received:
    26
    Thanks for the script! It's set to pop just once per 24h correct?

    I would also, like waynem80, want to know how to make it pop full size if possible :)
     
  8. Black$ide

    Black$ide Registered Member

    Joined:
    Feb 2, 2011
    Messages:
    87
    Likes Received:
    69
    Occupation:
    Internet Magician
    Location:
    In Your Subconscious
    Wow, I tried this code and it worked..! +rep :)

    Interesting how long this will work, browsers are updating often ../
     
  9. andy2009

    andy2009 Junior Member

    Joined:
    Apr 18, 2009
    Messages:
    164
    Likes Received:
    26
    It works almost a little to great LOL.. :) is there a way to limit the popunder so it only pops once per domain even if the javascript is loaded on another sub-domain the 2nd time?

    I tried this but it didn't work:
    setCookie('popundr', 1, 24*60*60*1000,'/', document.domain.match(/\.(.*?(com|org|net))/)[1]);
     
  10. alexking

    alexking Jr. VIP Jr. VIP

    Joined:
    Jun 29, 2011
    Messages:
    107
    Likes Received:
    25
    Gender:
    Male
    Location:
    Canada
    Awesome, thanks was looking for something like this
     
  11. adbox

    adbox Power Member

    Joined:
    May 1, 2009
    Messages:
    658
    Likes Received:
    107
    Home Page:
    Big thanks super awesome!
     
  12. brtea

    brtea Newbie

    Joined:
    Mar 3, 2008
    Messages:
    9
    Likes Received:
    0
    How could the following scenario be done using this script?

    1. User signs up for my newsletter. (I use aweber)
    2. They confirm their email address and they're taken to my thank you page.
    3. I have this javascript code on my thank you page
    4. They close their browser and there sits my popunder with an email submit offer.

    Is there any way to pass the users email to prepopulate the popunder?
     
  13. 4don4i

    4don4i Newbie

    Joined:
    Sep 23, 2011
    Messages:
    22
    Likes Received:
    1
    thank's for this usefull post for me who learn codding.
     
  14. briannz

    briannz Junior Member

    Joined:
    Mar 18, 2010
    Messages:
    119
    Likes Received:
    22
    Location:
    Aotearoa
    Works Perfectly! Bene looking for something that works for ages.
     
  15. briannz

    briannz Junior Member

    Joined:
    Mar 18, 2010
    Messages:
    119
    Likes Received:
    22
    Location:
    Aotearoa
    It doesn't seem to work properly in IE8. It pops under ok, but then appears in the foreground, over the top of the website. Anyone else noticed this?
     
  16. adbox

    adbox Power Member

    Joined:
    May 1, 2009
    Messages:
    658
    Likes Received:
    107
    Home Page:
    I did, but I modified something to make it work. I'm looking over the code now and having trouble remember what affected it to make it work. I'll just post my code. I'm not sure it will work Out-of-the-box though; made need some tinkering.

    Code:
    <script>
                                            var pshow = false;
    					var PopFocus = 1;
    					var _Top = null;
                                            var is_popunder =1;
                                            
    
    					function GetWindowHeight() {
    						var myHeight = 0;
    						if( typeof( _Top.window.innerHeight ) == 'number' ) {
    						myHeight = _Top.window.innerHeight;
    						} else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
    						myHeight = _Top.document.documentElement.clientHeight;
    						} else if( _Top.document.body && _Top.document.body.clientHeight ) {
    						myHeight = _Top.document.body.clientHeight;
    						}
    						return myHeight;
    					}
    
    					function GetWindowWidth() {
    						var myWidth = 0;
    						if( typeof( _Top.window.innerWidth ) == 'number' ) {
    						myWidth = _Top.window.innerWidth;
    						} else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
    						myWidth = _Top.document.documentElement.clientWidth;
    						} else if( _Top.document.body && _Top.document.body.clientWidth ) {
    						myWidth = _Top.document.body.clientWidth;
    						}
    						return myWidth;
    					}
    
    					function GetWindowTop() {
    						return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
    					}
    
    					function GetWindowLeft() {
    						return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
    					}
    
    					function openp(url)
    					{
    						var popURL = "about:blank";
    						var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
    						var pxLeft = 0;
    						var pxTop = 0;
    						pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (<?php echo $popups_width[$key]; ?> / 2));
    						pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (<?php echo $popups_height[$key]; ?> / 2));
    
    						if ( pshow == true )
    						{
    						return true;
    						}
    
    						var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=' + pxTop + ',left=' + pxLeft + ',width= <?php echo $popups_width[$key]; ?> ,height= <?php echo $popups_height[$key]; ?>');
    
    						if (PopWin)
    						{
    							pshow = true;
    							
    							
    							if (PopFocus == 0)
    							{
    								PopWin.blur();
    
    								if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
    								{
    									_Top.window.blur();
    									_Top.window.focus();
    								}
    							}
    
    							PopWin.Init = function(e) {
    
    								with (e) 
    								{
    
    									Params = e.Params;
    									Main = function(){
    										
                                                                             if (is_popunder==1)
                                                                             {
    											var popURL = Params.PopURL;
    											PopWin.Params = {PopURL: url };
    											if (typeof window.mozPaintCount != "undefined") {
    												var x = window.open(popURL);
    												//x.close();
    												
    												}
    											
    
    											window.location = popURL;
    										}
    else
    {
    											var popURL = Params.PopURL;
    											if (typeof window.mozPaintCount != "undefined") {
    												var x = window.open("about:blank");
    												x.close();
    												
    
    											}
    											try { opener.window.focus(); }
    											catch (err) { }
    
    											window.location = popURL;
    
    											
    										}
    											
    									};
    
    									Main();
    								}
    							};
    
    							PopWin.Params = {PopURL: *****;
    
    							PopWin.Init(PopWin);
    						}
    
    						return PopWin;
    					}
    
    					function setCookie(name, value, time)
    					{
    						var expires = new Date();
    
    						expires.setTime( expires.getTime() + time );
    
    						document.cookie = name + '=' + value + '; path=/;' + '; 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 gopop()
    					{
    						_Top = self;
    
    						if (top != self)
    						{
    							try
    							{
    							if (top.document.location.toString())
    							_Top = top;
    							}
    							catch(err) { }
    						}
    						
    
    						if ( document.attachEvent )
    						{
    							document.attachEvent( 'onclick', checkTarget );
    						}
    						else if ( document.addEventListener )
    						{
    							document.addEventListener( 'click', checkTarget, false );
    						}						
    					}
    
    					function checkTarget(e)
    					{
    						//alert(wptt);
    						if ( !getCookie('thispop') || wptt ==1) {
    							var e = e || window.event;
    							openp('PLACEPOPUPURLHERE');
    							setCookie('thispop', 1, 60*60*2);
    						}
    					}
    
    					gopop();
    					</script>
    
    It should be mentioned that I've made the popup/popunder features available and easily customizable within my WPTrafficTools plugin for Wordpress.
     
  17. sean3000

    sean3000 Newbie

    Joined:
    Jan 15, 2011
    Messages:
    23
    Likes Received:
    27
    Works perfectly in FF and Chrome, haven't tested in IE.
     
  18. barcodeunit

    barcodeunit Junior Member

    Joined:
    Feb 21, 2009
    Messages:
    159
    Likes Received:
    24
    i need a modification to this script. Someone who knows javascript PM me i will pay them.
     
  19. lacy1978

    lacy1978 Junior Member

    Joined:
    Jan 5, 2011
    Messages:
    153
    Likes Received:
    39
    Can you use this script if you have Adsense on your site?

    From the help page: Sites may not change user preferences, redirect users to unwanted websites, initiate downloads, include malware or contain pop-ups or pop-unders that interfere with site navigation.

    Since it isn't "interfering with site navigation" this method should be fine correct?
     
    Last edited: Mar 12, 2012
  20. exXtr@

    exXtr@ Power Member

    Joined:
    Aug 27, 2009
    Messages:
    526
    Likes Received:
    246
    Occupation:
    IM
    Location:
    Belgium
    update on the scripts : script 1 pops under in ie9 , opens new tab in firefox. Script 2 seems to have an error on this line : PopWin.Params = {PopURL: *****;


    Anyone that has any updated code that works ?