Click to See Complete Forum and Search --> : Requesting Script: popup on leave


Sal Collaziano
02-12-2003, 04:52 PM
Hi all. I'm looking for a script that will popup when someone either types in a different URL to leave my site OR clicks the "x" to close their browser. Sort of a "before you leave, why not sign up for our free newsletter" kind of thing..

I'd like to have the script on every page so that no matter where someone decides to leave from, it'll popup. But, I don't want it to popup on each page they view and browse away from to a link somewhere on my site.

Can someone help me?

Thank you...

Jona
02-12-2003, 07:04 PM
Oooooh, yes, I get it... Well, you may try...

<body onUnload="openIT()">

And an IF..

function openIT() {
if(document.referrer=="previousPage.html") { return false; }
else { window.open('exit.htm','exit','config') }
}

Note that it won't work in all browsers, as "document.referrer" is not an object to some browsers. So it won't always work..

AdamBrill
02-12-2003, 07:53 PM
Jona - This checks the previous page. What they wanted is when the user leaves their site. So, you would have to get the page they are going to, which I don't think is possible...

Charles
02-12-2003, 08:08 PM
<script type="text/javascript">
<!--
window.onunload = function () {window.open('http://www.w3.org')}

/* the following will, once the document is loaded, step through all of the links on the page and set each link, when clicked, to clear the above handler */

window.onload = function () {for (var i=0; i<document.links.length; i++) {document.links[i].onclick = function () {window.onunload = function () {}}}}
// -->
</script>

Jona
02-12-2003, 08:16 PM
WHOOPS! Duh! Haha! Yea... boy, that was dumb! Hahaha!! Sorry! LOL!!