views:

61

answers:

3

Is there a way to escape a loop like the one below without closing the browser by terminating it process?

WARNING: Don't run the code below. Running this code will throw your browser in an infinite loop of alerts.

<html><body onload="while(true)alert('Hello')"></body></html>
+1  A: 

Some browsers will disallow this from happening in the first place.

Whenever this does happens to me, I do my best to do the following key sequence quickly:

[ENTER] Ctrl+W

Which will escape the loop and close the window/tab, but shouldn't terminate the browser.

EDIT I shouldn't say it escapes the loop. It closes the window which prevents that page from executing anymore javascript.

Jamie Wong
A: 

On Firefox, install the Firebug plugin. Among many other useful features, it allows you to debug javascript code.

Craig Trader
+4  A: 

Firebug plug-in for FireFox, mentioned in another answer, is one, albeit overly-powerful, option.

A more targeted one is an AlertCheck plug-in.

Here's a screenshot of the checkbox it adds to alert dialogs:

alt text

For non-FireFox browsers, there's no generic answer aside from really quick Ctrl+W after clicking/ENTER-ing "OK" which is hard to make work (and may not work on Internet Explorer 6 which IIRC doesn't do Ctrl-W).

DVK
+1 Hadn't heard of the plugin, Thanks
Jamie Wong
@DVK - Chrome and Opera offer the option to suppress further messages natively without plugins. Safari does not have one as far as I know.
Anurag