Click to See Complete Forum and Search --> : Pop Up On Exit - 'Back Button Problem'


lanidex2
06-06-2003, 07:46 AM
We're using a script that opens a pop up window when a user exits the site. However, it also brings up the pop up when a user hits refresh or the Back button. Is there any way to stop this from happening? I've included the script below:

<script type="text/javascript">
<!--
window.onunload = function () {window.open('popup.html','','toolbar=no,menubar=no,location=no,height=420,width=430');
}

/* 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>


</head>

Thank you!

Jona
06-06-2003, 01:58 PM
It's not possible to check and see if the Back button was clicked, since the back button has no event handler and is not a part of the document object, you cannot access it (not even with the window object).

Unless I'm proven wrong, :)
Jona

goofball
06-06-2003, 02:11 PM
There's no way to rule OUT the methods that you don't want
to trip the popup window (i.e. the back button, refresh, etc)
because the "onUnload" event handler is triggered every time
the page is unloaded, regardless of HOW it's unloaded.

In stead, I would suggest attaching the popup window
function to the methods that you do want to trigger it.
Like on all of your links leading off the site, add some inline
event handler: onClick="popup();"
You could also offer a "Close Window" button & attach the
same inline code.

lanidex2
06-06-2003, 03:03 PM
Is there anyway to associate the function with the actual url, as in, leaving the url brings up the pop up. That way, even if you hit the back button, you're still on the same url. Sorry if this is a stupid question.

brendandonhue
06-06-2003, 03:57 PM
No-you can not detect the URL someone is going to next.