Forum Moderators: open
Can anyone point me in the direction of a script that will:
- launch a pop-under when a user leaves my site
- does not launch the pop-under when they simply leave a page with the script on to go to another page on my site
and ideally
- doesn't lauch a pop-under when a user clicks a link to an external site that opens in a new window
- doesn't require anything to be added to the <body> tag
var link_glob=0;
window.onunload=function(){
if(link_glob==0)popunder_code;
}
Your links would look something like:
<a href="http://mysite_files" onclick="link_glob=1;">My Page</a>
Anyway ... isn't there a way to accomplish this with cookies?
var alllinks = document.links;
for (var i = 0; i < alllinks.length; i++) {
alllinks[i].onclick = function() {link_glob=1;};
}
This script should be executed when the document is fully loaded, i.e. by putting it at the end of your page or by triggering it with document.body.onload or <body onload="...">
Disclaimer: untested.
I don't see how it could be done with cookies; can't think of a step-by-step algo including cookies, as they don't execute script. Correct me if I'm wrong.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var link_stat=false;
window.onunload=function(){
if(!link_stat)alert("whoa"); //here, instead of the alert you would have your popunder code
}
function testLinks(){
var ln=document.links.length;
for(var i=0;i<ln;i++){
document.links[i].onclick=function(){
var test_url=/javascript:alert\('d/i;
// test_url is a regular expression to match "javascript:alert('d" ~etc. domain
//set the expression, between the forward slashes, to match your domain
var lnk_url=this.href;
link_stat=test_url.test(lnk_url);
alert(link_stat);
return true;
};
}
}
</script>
</head>
<body onload="testLinks();">
<p>
<a href="javascript:alert('duh');history.go(0);">
<!-- the history.go(0) method is invoked to simulate the setting of link_stat at page load -->
Click here for a "javascript:alert('duh');" URL test</a>
</p>
<p>
<a href="http://www.webmasterworld.com/forum91/2193.htm">Click here for this thread's URL</a>
</p>
<p>
<a href="javascript:alert('d\'oh');history.go(0);">Click here for a "javascript:alert('d\'oh');"" URL</a>
</body>
</html>
I've always been led to believe that the jumping out windows is more of a C++ thing; not so much JavaScript. Did I miss a memo?