Escaping an infinite loop without terminating the browser
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>
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 any more javascript.
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:
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).
On Firefox, install the Firebug plugin. Among many other useful features, it allows you to debug javascript code.
精彩评论