Home > Programming, Servers & Scripts >

[SCRIPT] Pop Under & Open In New Tab/Window (15)


09-19-2011 10:01 AM #1 tijn (Moderator)
[SCRIPT] Pop Under & Open In New Tab/Window

I had a request from nils for a script that enables you to:

1) click link & open link in new Tab
2) load a 2nd link in a pop under window

After some trial and error, and using my favourite source for solving coding problems, I put together a script that solves it.

I have tested it on:

Mac:

Chrome - all ok, new tab gets focus depending on browser config
Firefox - all ok, new tab gets focus depending on browser config
Safari - ok, but page opens in new window rather then tab - this could be my config settings

Windows

IE 8 - With popup blocker on, it will still load the pop but as a popup not a popunder
FF 3.6 - Working but new tab loads with focus. You have to load the link with target="_blank" otherwise the popunder will not show!


I'd be interested in anyone testing it on Windows.

You can try it out here:

http://30m.org/stm/popunder.html

And here is the code:

Code:
<!DOCTYPE>
<html>
<head>
<script>
//Use to define popunder settings - dont incl Width/Height
var puSettings = "toolbar=0,statusbar=1,resizable=1,scrollbars=0,menubar=0,location=1,directories=0"; 

//Use to set width & height
var puWidth = 600;
var puHeight = 400;

//Use to define url to load in popunder
var puUrl = "http://www.google.com/search?q=popunder"; 

//Define PopUnder Object
var popUnder = {};
var winName = 'tijn_popunder';
popUnder.popped = 0;

popUnder.createCookie = function(name, value, hour) {
    var cookieTTL = 60 * 60 * 1000 * hour;
    var date = new Date();
    date.setTime(date.getTime() + (cookieTTL));
    var cookieExpires = (cookieTTL != 0) ? '; expires=' + date.toGMTString() : '';
    document.cookie = name + '=' + value + cookieExpires + '; path=/';
};

popUnder.getCookie = function(name) {
    var cookieResults = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
    if (cookieResults) {
        return (unescape(cookieResults[2]));
    } else {
        return null;
    }
};

popUnder.popunder = function(url, popunderWidth, popunderHeight) {
    if (popUnder.popped > 0) {
        return false
    }
    popUnder.popped++;
    
    var wFeatures = puSettings;
    if (navigator.userAgent.indexOf('Chrome') != -1) {
        wFeatures = "scrollbar=yes";
    }
    popUnder.pu_window = open('about:blank', winName, wFeatures + ",height=" + popunderHeight + ",width=" + popunderWidth);
    var regex = new RegExp(/rv:[2-9]/);
    if (regex.exec(navigator.userAgent)) {
        try {
            popUnder.pu_window.tryAgain = function() {
                if (regex.exec(navigator.userAgent)) { // Gecko 2+
                    this.window.open('about:blank').close();
                }
            };
            popUnder.pu_window.tryAgain();
        } 
        catch (err) {
        }
    }
    setTimeout(window.focus);
    window.focus();
    try {
        popUnder.pu_window.blur();
    } 
    catch (err) {
    }
    
    return true;
};

popUnder.checkPopunderTimerId = null;

popUnder.checkPopunder = function() {
    if (popUnder.pu_window && typeof (popUnder.pu_window) == "object" && popUnder.pu_window.closed) {
        popUnder.createCookie(winName, 2, 24);
    } 
    else {
        setTimeout('popUnder.checkPopunder();', 500);
    }
};

popUnder.init = function() {
    var cookieValue = popUnder.getCookie(winName);
    if (cookieValue == 1) {
        try {
            popUnder.pu_window = window.open('', winName);
            popUnder.pu_window.location.href = puUrl;
        } 
        catch (err) {
            popUnder.createCookie(winName, 2, 24);
        }
        popUnder.checkPopunderTimerId = setTimeout('popUnder.checkPopunder();', 500);
    }
};

popUnder.click = function() {
    var cookieValue = popUnder.getCookie(winName);
    if (cookieValue == null) {
        var ret = popUnder.popunder(puUrl, puWidth, puHeight);
        if (ret) {
            popUnder.pu_window.location.href = puUrl;
            popUnder.createCookie(winName, 1, 0);
            
            if (popUnder.checkPopunderTimerId == null) {
                popUnder.checkPopunderTimerId = setTimeout('popUnder.checkPopunder();', 500);
            }
        }
    }
    if (cookieValue == 1) {
        if (popUnder.pu_window && typeof (popUnder.pu_window) == "object" && popUnder.pu_window.closed) {
            popUnder.createCookie(winName, 2, 24);
        }
    }
};

if (document.addEventListener) {
    document.addEventListener('click', popUnder.click, false);
    document.addEventListener('unload', popUnder.checkPopunder, false);
} 
else {
    document.attachEvent('onclick', popUnder.click);
    document.attachEvent('onunload', popUnder.checkPopunder);
}

popUnder.init();

popUnder.load = 1;
</script>
</head>
<body>
<CENTER>
<a href="http://www.google.com/search?q=new+window" target="_blank">Click Here To open Pop Under & Load new page in Tab</a><br/>
<a href="http://www.google.com/search?q=same+window">Click Here To open Pop Under & Load new page in current Tab</a>

</center>
</body>
</html>

Have fun!!!


09-19-2011 10:10 AM #2 chris_m (Member)

Oooooo... lots of devious plans forming now to capture some extra bank out of clickers...


09-19-2011 10:24 AM #3 tijn (Moderator)

yep -> you can use this for anything really - in particular loading a multi offer lander that then links through to a bunch of other offers


09-19-2011 10:49 AM #4 ppvnewbie (Member)

2nd link doesn't pops for me but loads the site in the actual tab. I am on Win7 with FF 3.5.8 (might be not working cause of the tab mix plus add-on).


09-19-2011 11:01 AM #5 tijn (Moderator)

Thanks for that. I just tried myself with FF3.6 on windows and can confirm that if you use the 2nd link that the popup will not show.

Ill see if I can find a fix for this.


09-19-2011 11:43 AM #6 index (Member)

do you know how to modify it so if somebody does NOT click an affiliate link on your lander (and x's out the page), a popunder spawns so you can pitch them something different? kind of like your own personal TrafficVance on your landing pages


09-19-2011 11:51 AM #7 tijn (Moderator)

Most browsers dont allow you to popup a window unless the user clicks an object or link.

what you can do, and I have seen email submits do this a lot, is to load a new offer in a hidden iframe, and as soon as they try and exit, the script hides the original page, shows the hidden iframe with the new offer, and pops up a "Are you sure" Javascript confirmation message.

Here is some code that I think does that, but I havent tested this. I saved it a while back but never went back to make sure it was working. Cant remember where I got it from but I spotted it from a Clickbank product.

Code:
var exitsplashpage = 'http://ehotitems.traffichut.hop.clickbank.net/?tid=vex';

if (typeof jQuery == 'undefined') {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js';
    script.type = 'text/javascript';
    head.appendChild(script);
}

var PreventExitSplash = false;
var exitperiodrb = 0;
var periodEnable = 0;
var peroidDisable = 0;
var displayFrequency = 0;
var ESRecordId = '1311803953693';
var exitsplashmessage = '***************************************\n\n W A I T   B E F O R E   Y O U   G O !\n\n   CLICK THE *Stay on this page* BUTTON OR\n     THE *Cancel* BUTTON RIGHT NOW\n     TO STAY ON THE CURRENT PAGE.\n\n WE HAVE SOMETHING VERY SPECIAL FOR YOU!\n\n***************************************';
var alertmessage = '';
var UseAlert = 0;
var UseAudio = 0;
var AudioRB = '';
var UseHelper = 1;
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload()
            }
            func()
        }
    }
}
function addClickEvent(a, i, func) {
    if (typeof a[i].onclick != 'function') {
        a[i].onclick = func
    }
}
disablelinksfunc = function() {
    var a = document.getElementsByTagName('A');
    for (var i = 0; i < a.length; i++) {
        if (a[i].target !== '_blank') {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = true
            })
        } else {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = false
            })
        }
    }
}
disableformsfunc = function() {
    var f = document.getElementsByTagName('FORM');
    for (var i = 0; i < f.length; i++) {
        if (f[i].target !== '_blank') {
            if (!f[i].onclick) {
                f[i].onclick = function() {
                    PreventExitSplash = true
                }
            } else if (!f[i].onsubmit) {
                f[i].onsubmit = function() {
                    PreventExitSplash = true
                }
            }
        }
    }
}
function hideexitcancelbuttonimage() {
    document.getElementById('ExitCancelButtonImageDiv').style.display = 'none';
}
function StopExitImpactAudio() {
    var esDiv = document.getElementById('ExitSplashTopContainerDiv');
    var esiaDiv = document.getElementById('playaudio');
    if (StopAudio == 1) esDiv.removeChild(esiaDiv);
}
function esuniqid() {
    var newDate = new Date;
    return newDate.getTime()
}
function getDocHeight() {
    var D = document;
    return Math.max(D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight)
}
function createESCookie(name, value, seconds) {
    if (seconds) {
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        var expires = "; expires=" + date.toGMTString()
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/"
}
function readESCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
    }
    return null
}
function eraseESCookie(name) {
    createCookie(name, "", -1);
}
if (exitperiodrb == 1) {
    PreventExitSplash = true;
    setTimeout(function() {
        PreventExitSplash = false
    },
    periodEnable * 1000)
} else if (exitperiodrb == 2) {
    setTimeout(function() {
        PreventExitSplash = true
    },
    peroidDisable * 1000)
} else if (exitperiodrb == 3) {
    if (readESCookie('eswpcookie' + ESRecordId) != null) {
        PreventExitSplash = true
    } else {
        createESCookie('eswpcookie' + ESRecordId, 'yes', displayFrequency);
        PreventExitSplash = false
    }
} else {
    if (readESCookie('eswpcookie' + ESRecordId) != null) eraseESCookie('eswpcookie' + ESRecordId)
}
addLoadEvent(disablelinksfunc);
addLoadEvent(disableformsfunc);
window.onbeforeunload = function() {
    if (PreventExitSplash == false) {
        PreventExitSplash = true;
        window.scrollTo(0, 0);
        if (UseAudio == 1) $("#ExitSplashDiv").append('<embed wmode="transparent" src="http://exitsplash.s3.amazonaws.com/player.swf?url=' + AudioRB + '&mode=play&autostart=true&' + esuniqid() + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1" height="1"></embed>');
        $("#ExitSplashBackDiv").show();
        $("#ExitSplashDiv").show();
        setTimeout('window.location="' + exitsplashpage + '"', 10);
        var ua = $.browser;
        var ver = ua.version.slice(0, 1);
        var verInt = parseInt(ver);
        if ((UseAlert == 0) && (ua.mozilla) && (verInt >= 2)) {
            if (!confirm(exitsplashmessage)) {
                if (UseHelper == 1) $("#ExitSplashImpactImage").attr('src', 'http://exitsplash.s3.amazonaws.com/files/firefox.gif');
                return exitsplashmessage
            }
        } else {
            if (UseAlert == 1) window.alert(alertmessage);
            return exitsplashmessage
        }
    }
}

document.write('
<div id = "ExitSplashDiv"style = "display:none;position:absolute;right:10px;top:10px;margin:auto;z-index:1000;" > 
<center> 
<img id = "ExitSplashImpactImage"src = "http://exitsplash.s3.amazonaws.com/files/exitimpactimage11.gif"border = "0" / >
</center>
</div> 
<div id = "ExitSplashBackDiv"style = "display:none;position:absolute;left:0px;top:0px;overflow:auto;height:100%;width:100%;background:rgb(0, 0, 0);opacity:0.6;filter:alpha(opacity=60);z-index:999;">
</div>');


09-19-2011 12:07 PM #8 index (Member)

I put that code above in a basic webpage and tried it on my localhost, but it doesn't seem to be working. I know basic programming, but that script looks pretty intense lol

Code:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="keywords" content="keyword1,keyword2" />
  <meta name="description" content="Description" />
  <meta name="robots" content="noindex,nofollow" />
  <title>Default XHTML</title>
  <link rel="stylesheet" type="text/css" href="style.css" />

</head>

<body>

<p>Lorem ipsum <a href="#">dolor sit amet</a>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<script type="text/javascript">
var exitsplashpage = 'http://ehotitems.traffichut.hop.clickbank.net/?tid=vex';

if (typeof jQuery == 'undefined') {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js';
    script.type = 'text/javascript';
    head.appendChild(script);
}

var PreventExitSplash = false;
var exitperiodrb = 0;
var periodEnable = 0;
var peroidDisable = 0;
var displayFrequency = 0;
var ESRecordId = '1311803953693';
var exitsplashmessage = '***************************************\n\n W A I T   B E F O R E   Y O U   G O !\n\n   CLICK THE *Stay on this page* BUTTON OR\n     THE *Cancel* BUTTON RIGHT NOW\n     TO STAY ON THE CURRENT PAGE.\n\n WE HAVE SOMETHING VERY SPECIAL FOR YOU!\n\n***************************************';
var alertmessage = '';
var UseAlert = 0;
var UseAudio = 0;
var AudioRB = '';
var UseHelper = 1;
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload()
            }
            func()
        }
    }
}
function addClickEvent(a, i, func) {
    if (typeof a[i].onclick != 'function') {
        a[i].onclick = func
    }
}
disablelinksfunc = function() {
    var a = document.getElementsByTagName('A');
    for (var i = 0; i < a.length; i++) {
        if (a[i].target !== '_blank') {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = true
            })
        } else {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = false
            })
        }
    }
}
disableformsfunc = function() {
    var f = document.getElementsByTagName('FORM');
    for (var i = 0; i < f.length; i++) {
        if (f[i].target !== '_blank') {
            if (!f[i].onclick) {
                f[i].onclick = function() {
                    PreventExitSplash = true
                }
            } else if (!f[i].onsubmit) {
                f[i].onsubmit = function() {
                    PreventExitSplash = true
                }
            }
        }
    }
}
function hideexitcancelbuttonimage() {
    document.getElementById('ExitCancelButtonImageDiv').style.display = 'none';
}
function StopExitImpactAudio() {
    var esDiv = document.getElementById('ExitSplashTopContainerDiv');
    var esiaDiv = document.getElementById('playaudio');
    if (StopAudio == 1) esDiv.removeChild(esiaDiv);
}
function esuniqid() {
    var newDate = new Date;
    return newDate.getTime()
}
function getDocHeight() {
    var D = document;
    return Math.max(D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight)
}
function createESCookie(name, value, seconds) {
    if (seconds) {
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        var expires = "; expires=" + date.toGMTString()
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/"
}
function readESCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
    }
    return null
}
function eraseESCookie(name) {
    createCookie(name, "", -1);
}
if (exitperiodrb == 1) {
    PreventExitSplash = true;
    setTimeout(function() {
        PreventExitSplash = false
    },
    periodEnable * 1000)
} else if (exitperiodrb == 2) {
    setTimeout(function() {
        PreventExitSplash = true
    },
    peroidDisable * 1000)
} else if (exitperiodrb == 3) {
    if (readESCookie('eswpcookie' + ESRecordId) != null) {
        PreventExitSplash = true
    } else {
        createESCookie('eswpcookie' + ESRecordId, 'yes', displayFrequency);
        PreventExitSplash = false
    }
} else {
    if (readESCookie('eswpcookie' + ESRecordId) != null) eraseESCookie('eswpcookie' + ESRecordId)
}
addLoadEvent(disablelinksfunc);
addLoadEvent(disableformsfunc);
window.onbeforeunload = function() {
    if (PreventExitSplash == false) {
        PreventExitSplash = true;
        window.scrollTo(0, 0);
        if (UseAudio == 1) $("#ExitSplashDiv").append('<embed wmode="transparent" src="http://exitsplash.s3.amazonaws.com/player.swf?url=' + AudioRB + '&mode=play&autostart=true&' + esuniqid() + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1" height="1"></embed>');
        $("#ExitSplashBackDiv").show();
        $("#ExitSplashDiv").show();
        setTimeout('window.location="' + exitsplashpage + '"', 10);
        var ua = $.browser;
        var ver = ua.version.slice(0, 1);
        var verInt = parseInt(ver);
        if ((UseAlert == 0) && (ua.mozilla) && (verInt >= 2)) {
            if (!confirm(exitsplashmessage)) {
                if (UseHelper == 1) $("#ExitSplashImpactImage").attr('src', 'http://exitsplash.s3.amazonaws.com/files/firefox.gif');
                return exitsplashmessage
            }
        } else {
            if (UseAlert == 1) window.alert(alertmessage);
            return exitsplashmessage
        }
    }
}

document.write('
<div id = "ExitSplashDiv"style = "display:none;position:absolute;right:10px;top:10px;margin:auto;z-index:1000;" > 
<center> 
<img id = "ExitSplashImpactImage"src = "http://exitsplash.s3.amazonaws.com/files/exitimpactimage11.gif"border = "0" / >
</center>
</div> 
<div id = "ExitSplashBackDiv"style = "display:none;position:absolute;left:0px;top:0px;overflow:auto;height:100%;width:100%;background:rgb(0, 0, 0);opacity:0.6;filter:alpha(opacity=60);z-index:999;">
</div>');
</script>

</body>
</html>


09-19-2011 12:32 PM #9 tijn (Moderator)

Heres the amended code which does work:

NOTE: THIS IS NOT THE CODE FOR THE POPUNDER WHICH IS INCL IN THE FIRST POST. THIS IS CODE FOR AN EXIT SPLASH & PAGE RELOAD.

Code:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="keywords" content="keyword1,keyword2" />
  <meta name="description" content="Description" />
  <meta name="robots" content="noindex,nofollow" />
  <title>Default XHTML</title>
</head>

<body>

<p>Lorem ipsum <a href="#">dolor sit amet</a>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<script type="text/javascript">
var exitsplashpage = 'http://google.com/search?q=exit+splash';

if (typeof jQuery == 'undefined') {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js';
    script.type = 'text/javascript';
    head.appendChild(script);
}

var PreventExitSplash = false;
var exitperiodrb = 0;
var periodEnable = 0;
var peroidDisable = 0;
var displayFrequency = 0;
var ESRecordId = '1311803953693';
var exitsplashmessage = '***************************************\n\n W A I T   B E F O R E   Y O U   G O !\n\n   CLICK THE *Stay on this page* BUTTON OR\n     THE *Cancel* BUTTON RIGHT NOW\n     TO STAY ON THE CURRENT PAGE.\n\n WE HAVE SOMETHING VERY SPECIAL FOR YOU!\n\n***************************************';
var alertmessage = '';
var UseAlert = 0;
var UseAudio = 0;
var AudioRB = '';
var UseHelper = 1;
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload()
            }
            func()
        }
    }
}
function addClickEvent(a, i, func) {
    if (typeof a[i].onclick != 'function') {
        a[i].onclick = func
    }
}
disablelinksfunc = function() {
    var a = document.getElementsByTagName('A');
    for (var i = 0; i < a.length; i++) {
        if (a[i].target !== '_blank') {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = true
            })
        } else {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = false
            })
        }
    }
}
disableformsfunc = function() {
    var f = document.getElementsByTagName('FORM');
    for (var i = 0; i < f.length; i++) {
        if (f[i].target !== '_blank') {
            if (!f[i].onclick) {
                f[i].onclick = function() {
                    PreventExitSplash = true
                }
            } else if (!f[i].onsubmit) {
                f[i].onsubmit = function() {
                    PreventExitSplash = true
                }
            }
        }
    }
}
function hideexitcancelbuttonimage() {
    document.getElementById('ExitCancelButtonImageDiv').style.display = 'none';
}
function StopExitImpactAudio() {
    var esDiv = document.getElementById('ExitSplashTopContainerDiv');
    var esiaDiv = document.getElementById('playaudio');
    if (StopAudio == 1) esDiv.removeChild(esiaDiv);
}
function esuniqid() {
    var newDate = new Date;
    return newDate.getTime()
}
function getDocHeight() {
    var D = document;
    return Math.max(D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight)
}
function createESCookie(name, value, seconds) {
    if (seconds) {
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        var expires = "; expires=" + date.toGMTString()
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/"
}
function readESCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
    }
    return null
}
function eraseESCookie(name) {
    createCookie(name, "", -1);
}
if (exitperiodrb == 1) {
    PreventExitSplash = true;
    setTimeout(function() {
        PreventExitSplash = false
    },
    periodEnable * 1000)
} else if (exitperiodrb == 2) {
    setTimeout(function() {
        PreventExitSplash = true
    },
    peroidDisable * 1000)
} else if (exitperiodrb == 3) {
    if (readESCookie('eswpcookie' + ESRecordId) != null) {
        PreventExitSplash = true
    } else {
        createESCookie('eswpcookie' + ESRecordId, 'yes', displayFrequency);
        PreventExitSplash = false
    }
} else {
    if (readESCookie('eswpcookie' + ESRecordId) != null) eraseESCookie('eswpcookie' + ESRecordId)
}
addLoadEvent(disablelinksfunc);
addLoadEvent(disableformsfunc);
window.onbeforeunload = function() {
    if (PreventExitSplash == false) {
        PreventExitSplash = true;
        window.scrollTo(0, 0);
        if (UseAudio == 1) $("#ExitSplashDiv").append('<embed wmode="transparent" src="http://exitsplash.s3.amazonaws.com/player.swf?url=' + AudioRB + '&mode=play&autostart=true&' + esuniqid() + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1" height="1"></embed>');
        $("#ExitSplashBackDiv").show();
        $("#ExitSplashDiv").show();
        setTimeout('window.location="' + exitsplashpage + '"', 10);
        var ua = $.browser;
        var ver = ua.version.slice(0, 1);
        var verInt = parseInt(ver);
        if ((UseAlert == 0) && (ua.mozilla) && (verInt >= 2)) {
            if (!confirm(exitsplashmessage)) {
                if (UseHelper == 1) $("#ExitSplashImpactImage").attr('src', 'http://exitsplash.s3.amazonaws.com/files/firefox.gif');
                return exitsplashmessage
            }
        } else {
            if (UseAlert == 1) window.alert(alertmessage);
            return exitsplashmessage
        }
    }
}

document.write('<div id = "ExitSplashDiv"style = "display:none;position:absolute;right:10px;top:10px;margin:auto;z-index:1000;" > <center> <img id = "ExitSplashImpactImage"src = "http://exitsplash.s3.amazonaws.com/files/exitimpactimage11.gif"border = "0" / ></center></div> <div id = "ExitSplashBackDiv"style = "display:none;position:absolute;left:0px;top:0px;overflow:auto;height:100%;width:100%;background:rgb(0, 0, 0);opacity:0.6;filter:alpha(opacity=60);z-index:999;"></div>');
</script>

</body>
</html>
Test it here:


http://30m.org/stm/exitsplash.html


09-19-2011 12:47 PM #10 index (Member)

^^^ hell yea! Winning!


09-19-2011 12:59 PM #11 polarbacon (Moderator)

this can be done easy weasy as well in wysiwyg web builder.....as you do it via the "onunload" event .....

for all you non coder types


http://baconate.me/inlineframe.html


**edit** was told that this isn't working on some browsers...


09-19-2011 01:10 PM #12 vidivo (Member)

Tested the pop under with traffic and most people dont even see the pop to even bother with it...

Most Explorers these days block this stuff automatically anyways


09-19-2011 03:07 PM #13 nils (Member)

Tijn. Thanks A Lot. Works like a charm.


10-17-2011 08:21 PM #14 nils (Member)

Quote Originally Posted by tijn View Post
Heres the amended code which does work:

NOTE: THIS IS NOT THE CODE FOR THE POPUNDER WHICH IS INCL IN THE FIRST POST. THIS IS CODE FOR AN EXIT SPLASH & PAGE RELOAD.

Code:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="keywords" content="keyword1,keyword2" />
  <meta name="description" content="Description" />
  <meta name="robots" content="noindex,nofollow" />
  <title>Default XHTML</title>
</head>

<body>

<p>Lorem ipsum <a href="#">dolor sit amet</a>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<script type="text/javascript">
var exitsplashpage = 'http://google.com/search?q=exit+splash';

if (typeof jQuery == 'undefined') {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js';
    script.type = 'text/javascript';
    head.appendChild(script);
}

var PreventExitSplash = false;
var exitperiodrb = 0;
var periodEnable = 0;
var peroidDisable = 0;
var displayFrequency = 0;
var ESRecordId = '1311803953693';
var exitsplashmessage = '***************************************\n\n W A I T   B E F O R E   Y O U   G O !\n\n   CLICK THE *Stay on this page* BUTTON OR\n     THE *Cancel* BUTTON RIGHT NOW\n     TO STAY ON THE CURRENT PAGE.\n\n WE HAVE SOMETHING VERY SPECIAL FOR YOU!\n\n***************************************';
var alertmessage = '';
var UseAlert = 0;
var UseAudio = 0;
var AudioRB = '';
var UseHelper = 1;
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload()
            }
            func()
        }
    }
}
function addClickEvent(a, i, func) {
    if (typeof a[i].onclick != 'function') {
        a[i].onclick = func
    }
}
disablelinksfunc = function() {
    var a = document.getElementsByTagName('A');
    for (var i = 0; i < a.length; i++) {
        if (a[i].target !== '_blank') {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = true
            })
        } else {
            addClickEvent(a, i,
            function() {
                PreventExitSplash = false
            })
        }
    }
}
disableformsfunc = function() {
    var f = document.getElementsByTagName('FORM');
    for (var i = 0; i < f.length; i++) {
        if (f[i].target !== '_blank') {
            if (!f[i].onclick) {
                f[i].onclick = function() {
                    PreventExitSplash = true
                }
            } else if (!f[i].onsubmit) {
                f[i].onsubmit = function() {
                    PreventExitSplash = true
                }
            }
        }
    }
}
function hideexitcancelbuttonimage() {
    document.getElementById('ExitCancelButtonImageDiv').style.display = 'none';
}
function StopExitImpactAudio() {
    var esDiv = document.getElementById('ExitSplashTopContainerDiv');
    var esiaDiv = document.getElementById('playaudio');
    if (StopAudio == 1) esDiv.removeChild(esiaDiv);
}
function esuniqid() {
    var newDate = new Date;
    return newDate.getTime()
}
function getDocHeight() {
    var D = document;
    return Math.max(D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight)
}
function createESCookie(name, value, seconds) {
    if (seconds) {
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        var expires = "; expires=" + date.toGMTString()
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/"
}
function readESCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
    }
    return null
}
function eraseESCookie(name) {
    createCookie(name, "", -1);
}
if (exitperiodrb == 1) {
    PreventExitSplash = true;
    setTimeout(function() {
        PreventExitSplash = false
    },
    periodEnable * 1000)
} else if (exitperiodrb == 2) {
    setTimeout(function() {
        PreventExitSplash = true
    },
    peroidDisable * 1000)
} else if (exitperiodrb == 3) {
    if (readESCookie('eswpcookie' + ESRecordId) != null) {
        PreventExitSplash = true
    } else {
        createESCookie('eswpcookie' + ESRecordId, 'yes', displayFrequency);
        PreventExitSplash = false
    }
} else {
    if (readESCookie('eswpcookie' + ESRecordId) != null) eraseESCookie('eswpcookie' + ESRecordId)
}
addLoadEvent(disablelinksfunc);
addLoadEvent(disableformsfunc);
window.onbeforeunload = function() {
    if (PreventExitSplash == false) {
        PreventExitSplash = true;
        window.scrollTo(0, 0);
        if (UseAudio == 1) $("#ExitSplashDiv").append('<embed wmode="transparent" src="http://exitsplash.s3.amazonaws.com/player.swf?url=' + AudioRB + '&mode=play&autostart=true&' + esuniqid() + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1" height="1"></embed>');
        $("#ExitSplashBackDiv").show();
        $("#ExitSplashDiv").show();
        setTimeout('window.location="' + exitsplashpage + '"', 10);
        var ua = $.browser;
        var ver = ua.version.slice(0, 1);
        var verInt = parseInt(ver);
        if ((UseAlert == 0) && (ua.mozilla) && (verInt >= 2)) {
            if (!confirm(exitsplashmessage)) {
                if (UseHelper == 1) $("#ExitSplashImpactImage").attr('src', 'http://exitsplash.s3.amazonaws.com/files/firefox.gif');
                return exitsplashmessage
            }
        } else {
            if (UseAlert == 1) window.alert(alertmessage);
            return exitsplashmessage
        }
    }
}

document.write('<div id = "ExitSplashDiv"style = "display:none;position:absolute;right:10px;top:10px;margin:auto;z-index:1000;" > <center> <img id = "ExitSplashImpactImage"src = "http://exitsplash.s3.amazonaws.com/files/exitimpactimage11.gif"border = "0" / ></center></div> <div id = "ExitSplashBackDiv"style = "display:none;position:absolute;left:0px;top:0px;overflow:auto;height:100%;width:100%;background:rgb(0, 0, 0);opacity:0.6;filter:alpha(opacity=60);z-index:999;"></div>');
</script>

</body>
</html>
Test it here:


http://30m.org/stm/exitsplash.html
Hey, the exit splash also pops when I click the call to action button. How can I fix this?

Thanks


10-18-2011 10:24 AM #15 tijn (Moderator)

for any links that you dont want the exit pop to appear when pressed, include PreventExitSplash=true in the onclick event, something like this:

<a href="http://yourdomain.com" onclick="PreventExitSplash=true; return true;">Link</a>


Home > Programming, Servers & Scripts >