Some websites contain dubious listings that may prevent you from leaving the site. Henrik5000 / Getty ImagesMany disreputable sites employ a technique that leads to a frustrating situation: When you attempt to leave the site—whether by clicking the Back button or closing the browser window—the site reappears in a new window. In extreme cases, the site opens in multiple windows when you try to exit, leaving the only solution as shutting down your computer. Most people get trapped on these sites through search engine results that appear credible until you click on them.
Here’s how these sites operate. If you’ve read the Mytour article How Web Pages Work, you’ll know that the HTML code for the most basic web pages looks like this:
The content of the page is displayed here...!
The
tag defines the start of the page's content. You can customize the tag. For example, if you modify it like this, , the page’s background will turn yellow.All modern browsers now support a feature known as JavaScript, which allows you to embed code directly into a page. Using JavaScript, one of the attributes you can add to the
tag is onUnload. For instance, you can specify:This statement means, "When the browser tries to unload the page (whether by using the Back button or closing the window), execute the JavaScript function called replay." At the top of the page, the replay function is a small JavaScript function that looks like this:
//]]]]>]]>
When the replay function is triggered, you’ll notice that it simply opens a new window displaying the requested page (in this case, www.blahblahblah.com). The creator of the website can easily open multiple windows — by adding four more open commands to the replay function, five new windows will appear. If they all display the same content, your screen will quickly fill with dozens of windows, forcing you to shut down.
The use of the flag variable is interesting. It's there because when the page includes a link, clicking it triggers the onUnload function. As a result, the link will include the following code:
This deactivates the replay function if the user clicks on the link on the page.
There are many other less intrusive things you can do with JavaScript. This page contains numerous links.
These links will help you explore more:
- Understanding How Java Functions
- How Web Pages Operate
- The Mechanics of Computer Viruses
- What happened when someone took control of my computer via the Internet?
- JavaScript.com
- Yahoo! Directory: Java
