你如何在Javascript中停止无限循环? [英] How do you stop an infinite loop in Javascript?

查看:142
本文介绍了你如何在Javascript中停止无限循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我不小心写了这个:

Let's say I accidentally wrote this:

 do { } while (true);

...然后运行它。除了杀死你的浏览器,有没有办法停止javascript执行(相当于基本的Ctrl + Break,或Ctrl + C)?

...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)?

通常,大约30后秒你的浏览器询问你是否要停止长时间运行的脚本,但这并不总是发生(正如我刚刚发现的那样)!

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:一个简单的循环例如: for(i = 1; i> 0; ++ i); 将导致我的浏览器崩溃(Firefox 3.5b4)。我感觉不太像测试它是否是我的任何附加组件。连续重启我的浏览器不是我周一晚上的一个有趣的想法。

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.

推荐答案

至少在Chrome上,你可能能够杀掉单个标签而不是整个应用程序。

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

Randolpho 还告诉我,IE8具有类似的功能。

Randolpho has also informed me that IE8 has similar functionality.

这篇关于你如何在Javascript中停止无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆