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 '10 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.trex Jan 8 '10 at 6:01

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 '10 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 ( myself.

protected by BinaryMisfit Oct 26 '10 at 18:13

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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