Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Window | Q319 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.