Why is it that some Web pages seem to trap me so I can't get out?

A web address displayed on a computer screen.
Some websites have illegitimate listings that may prevent you from leaving the site. Henrik5000 / Getty Images

­ 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 window, 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 until you click on them.

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

Advertisement

    Content of the page goes here...!

The tag 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 , 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:

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

//]]]]>]]>

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 www.blahblahblah.com). There's nothing to stop the creator of the Web page from opening up multiple windows -- simply adding four more open lines to the replay function will cause five 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:

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. This page has lots of links.

Advertisement

Frequently Answered Questions

Why do Web pages get stuck?
There are many reasons why web pages get stuck. It could be due to a slow internet connection, a problem with the website's server, including too many open programs or tabs, or a problem with the browser itself.
Why can't I back out of certain websites?
Some websites do not allow users to back out of them because the website wants the user to stay on the site and continue using it. Other websites may not allow users to back out because the website is not working properly or the user's internet connection is not strong enough.

Advertisement

Loading...