1. Home
  2. Computing & Technology
  3. JavaScript

Block Exit Blockers User Script

clr gif

With popup blockers you can block those annoying popups that some pages insist on displaying when you first visit a web page or when you try to leave. Some web sites have now taken to trying to block you from leaving their page by using an in page overlay that pops into the page when you try to leave to ask you to reconsider. These exit blockers are just about as annoying as the popups that they have replaced.

These exit blockers can't use the onunload event handler to trigger their desired processing because when that runs the page is already starting to be unloaded from the browser and it is too late to stop the unload from proceeding. Instead these exit blockers nust be being triggered by the proprietary event handler onbeforeunload that some browsers such as Internet Explorer and Firefox support but which other browsers such as Opera do not. One solution to getting around these exit blockers therefore is to switch to using a browser that does not support the proprietary event handler that triggers them to run.

If you don't want to switch browsers in order to solve this annoyance by using a browser that doesn't support the event then what you need to do is to disable the event in the browser that you are using instead. One way of doing this is to install a user script into your browser that overrides whatever the page has attached to that event handler with null.

The exitblock.user.js script just needs to be installed into your particular browser. For Firefox/Greasemonkey simply click the link and select "Install User Script". To use the script with IE simply click on the link to display the script then copy it into a text editor and save it as "exitblock.ieuser.js" into the IE7pro userscript folder.

Note that not all exit blockers will necessarily use the onbeforeunload event to trigger the block and those that don't will still appear in your browser with this userscript installed.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.