Many sites of ill repute use a technique that causes the following distressing situation - when you try to leave the site, either by using the Back button or by closing the browser, the site reappears in a new window. In the worst cases, the site pops up in three or four new windows when you try to leave it, and basically the only way out is to shut down your computer. The way most people get trapped into these sites is through listings in search engines that look legitimate but clearly are not once you click on them.

The way these sites work is as follows. If you have read the HSW article entitled How Web Pages Work, you know that the HTML code for the simplest web pages looks like this:

     <title>My First Page</title>
    Content of the page goes here...!

The tag <body> marks the beginning of the body of the page. You are allowed to modify the body tag. For example, if you change it so it looks like <body bgcolor=yellow>, then the background color of the page will be yellow.

All major browsers today support a capability called JavaScript, and JavaScript allows you to embed code in a page. Using JavaScript, one of the modifiers you can add to the body tag is onUnload. For example, you can say:

  <body onUnload="replay()">

This says, "When the browser attempts to unload the page (either by using the back button or by closing the browser), call the JavaScript function named replay". Then at the top of the page the function replay is a small JavaScript function that looks like this:

<SCRIPT language="Javascript">
    flag = 1;
    function replay() 
      if (flag==1) 
        open("", "New_Window"); 

When the replay function gets called, you can see that all it does is open a new window that contains whatever page is requested (here it's There's nothing to stop the creator of the web page from opening up multiple windows - simply adding 4 more "open" lines to the replay function will cause 5 new windows to open. If they all do the same thing, your screen quickly fills with dozens of windows. That's when you have to shut down.

The use of the flag variable is interesting. That's there because, if the page contains a link, it causes onUnload to get triggered when the link is clicked. So the link will contain the following code:

   <a HREF="javascript:showImage('');" onClick="flag=0">

This turns off the replay function if the user clicks the link on the page.

There are all sorts of other less annoying things you can do with JavaScript. has lots of links.