ARTLUNG LAB Share

Created 12/2001

onunload + window.open = evil

I was asked recently how the sites that that open windows when you close them do it? And the answer is that the authors of those sites have no hearts or brains. Well, actually, they do it by using the onunload event handler and the open() method of the window object.

It's a noxious combination.

Spend some time with the following demonstration, won't you?

  1. Open your text editor (Notepad or emacs or SimpleText)
  2. Select and copy the source cde below
  3. Save the document as onunload.htm
  4. Load it into a browser
  5. Experience the pleasure

After a while of playing whack-a-mole with the windows you will understand that opening windows onunload is a nasty idea. Leave it for the porn sites. With great power comes great responsibility, Kal-El.

Source Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "https://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
    <title>window.open and onunload used together are evil</title>
</head>
<body onunload="window.open('onunload.htm')">

<h1>Wow, this is annoying.</h1>

</body>
</html>