Free Javascript Popunder which works!

garundang

Registered Member
Joined
Apr 2, 2011
Messages
86
Reaction score
103
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>
 
im using it to my affliate site.
 
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.
 
thanks, was looking for a script that really worked. Test it 2 minutes ago and work perfect.
 
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 :)
 
Wow, I tried this code and it worked..! +rep :)

Interesting how long this will work, browsers are updating often ../
 
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]);
 
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?
 
Works Perfectly! Bene looking for something that works for ages.
 
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?
 
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.
 
i need a modification to this script. Someone who knows javascript PM me i will pay them.
 
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:
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 ?
 
Back
Top