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?
- Open your text editor (Notepad or emacs or SimpleText)
- Select and copy the source cde below
- Save the document as onunload.htm
- Load it into a browser
- 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.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://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>