tags:

views:

723

answers:

4

Let's say I accidentally wrote this:

 do { } while (true);

...and then ran it. Apart from killing your browser, is there a way to stop javascript execution (the equivalent of Ctrl+Break in basic, or Ctrl+C)?

Normally, after about 30 seconds your browser asks if you want to stop the long-running script, but this doesn't always happen (as I just found out)!

FYI: A simple loop such as this: for (i=1; i > 0; ++i); will cause my browser to crash (Firefox 3.5b4). I don't feel much like testing to see if it's any of my add-ons. Continuously restarting my browser isn't my idea of a fun Monday night.

+2  A: 

Depends on the browser. Some let you click the "stop" button to stop javascript execution. Others don't.

I suggest the best way is to just kill the browser entirely.

Randolpho
+4  A: 

At least with Chrome, you may be able to kill off the individual tab and not the whole application.

Randolpho has also informed me that IE8 has similar functionality.

alex
IE8 does this now, too.
Randolpho
Ah yes, I thought it may have.
alex
+4  A: 

Most browsers have a "slow script performance" warning that comes up when an out of control javascript is taking a very long time to execute. This warning dialog usually gives the option to kill the offending script.

Soviut
+1  A: 

most decent browsers do show an "unresponsive script" warning... If not, I guess your best course of action would be to find out why the warning is not popping up.

Here Be Wolves