It is possible for javascript to get stuck in a loop of opening up alerts. For example:

for(var i=0;;i++)
    alert('This will never stop');

Is there a way to gracefully stop this in firefox, without having to kill the whole process?

  • 1
    This isn't a satisfactory general-purpose solution, but with Greasmonkey (or maybe Ubiquity or Jetpack) you could overwrite window.alert with a function that calls window.confirm and optionally throw()s an error, stopping all script execution, or toggles a flag to stop alerts. That might be useful if a site you keep going back to presents this behavior.
    – Anonymous
    Jan 7, 2010 at 14:56
  • In Opera, each dialog has a checkbox saying "Stop executing scripts on this page", which when checked will solve the problem. Guess they should put it in firefox too.
    – Anand
    Jan 8, 2010 at 6:01

5 Answers 5


perhaps the 'NoScript' plugin could help. Ban the site and the script won't be executed at all


Stackoverflow question reference: How do you stop an infinite loop in Javascript?

A critical difference in your loop is the pop-up (user interaction) that prevents the "slow-script" detection.


If you're quick enough with it, click "Ok" then hit F5. You may have to confirm one or two more popups, but the page will reload and you'll be saved.

  • 3
    Page reload is useless if the rogue JS script runs when loading the page (a case I had). But you inspired me to do [Ctrl+] Return and Ctrl+W in a quick sequence and finally I got rid of the page... (Ctrl+Return works as Return but having this key down helps for speed hit Ctrl+W!) So +1 for you! :-)
    – PhiLho
    Mar 15, 2010 at 15:34

I usually have the Javascript popup in focus so that I can just hit Enter to get rid of it. Then, I position my mouse cursor just above the Close Tab button. I then begin a race where I hit Enter to close the popup and immediately click the Close Tab button before it has a chance to create another popup.


I'm using AlertStopper (https://addons.mozilla.org/af/firefox/addon/13530/) myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.