Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q319 How can I load a popup window when a user leaves my site?

You are here: irt.org | FAQ | JavaScript | Window | Q319 [ previous next ]

It'll be difficult to do, unless you trap all foreign links out of a document so that before the link is gone to it loads a popup window.

This does not however work if the user types in a url, selects a bookmark, clicks on the back button, or selects a url from the history:

<a href="http://www.yahoo.com" onClick="window.open('goodbye.html','myname')">Go to Yahoo</a>

The following was submitted by Jos Juffermans:

You can simply use the unload event in the body tag... However, I've had my page opening a window un exit, but I got realy tired of it pretty soon. Most users don't like popups opening... Note: If you use frames, be carefull in which page to place your onunload event... This works fine on Internet Explorer, but you may have to capture the event on Netscape Navigator.

<html>
<head>
<script language="JavaScript">
   function MyExit() {
      window.open('thankyou.html');
   }
</script>
</head>
<body onUnload="MyExit();">
your main page...
</body>
</html>

Feedback on 'Q319 How can I load a popup window when a user leaves my site?'

©2018 Martin Webb