Click to See Complete Forum and Search --> : JS: Opening a separate popup window on exit!!!!


lastat
01-15-2003, 10:21 AM
Hi, I am Robert. I have been desperatelly strugling with the following Java Script problem:

I was told to create a pupup questionnaire that is to open in a separate popup window only when a user exits or leaves the current web page. That means if user either closes the browser window or presses the back button or types a different URL.

I have partially done so but when I browse inside the web page ( I mean whenever I click on links on this web page) the popup comes on each time ... and I DO NOT WANT IT POPPING UP each time I click on a link.

Is there a command like onExit which should ensure that if the current URL is changed or left it triggers the popup???

Please , help me....... :-(

Thanks a lot, ROBERT

Charles
01-15-2003, 10:29 AM
The following in the document head ought to do the trick for you:

<script type="text/javascript">
<!--
window.onload = function() {for (j=0;j<document.links.length;j++) {document.links[j].onclick = function () {window.onunload = function() {}}}}
// -->
</script>

lastat
01-15-2003, 12:01 PM
Coming back to my problem with popup on exit:

Now that I was kindly given the solution, I implemented it and with IE6x and NS6x it seems to work as I wanted but with
previous versions it does not.

That means that the popup comes on each time when a link inside the page is clicked and it should only popup when exiting the page where it is nested.


Can you give me a hint how to correct this in JavaScript???


Thanks

Rob:confused:

Charles
01-15-2003, 12:55 PM
There's nothing about that script that is browser dependent. Perhaps it's not not working well woth something else in your page. Try adding the following to one of your links and give it a try:

onclick="window.onunload = function(){}"