javascript 停止运行这个脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5667456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stop running this script
提问by Rocket Hazmat
Stop running this script?
A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer might become unresponsive.
停止运行此脚本?
此页面上的脚本导致 Internet Explorer 运行缓慢。如果它继续运行,您的计算机可能会变得无响应。
I'm sure we've all seen this useful and informative error message from IE7 (or rather IE8 in IE7 mode). I need some help with removing this message.
我相信我们都看到过这个来自 IE7(或者更确切地说是 IE7 模式下的 IE8)的有用且信息丰富的错误消息。我需要一些帮助来删除此消息。
So, for my work, I need to get our website working in IE7. Apparently, some of our clients can't upgrade or use another browser (corporate regulations or something).
因此,对于我的工作,我需要让我们的网站在 IE7 中运行。显然,我们的一些客户无法升级或使用其他浏览器(公司规定或其他)。
Anyway, the page in question contains tabs (using jQueryUI). After the page loads, jQuery loads the data for each tab using AJAX; the tabs are loaded one by one, using a queue. In each tab, there are 'widgets' which contain HTML and JavaScript (for each tab load, there are various script tags).
无论如何,有问题的页面包含选项卡(使用 jQueryUI)。页面加载后,jQuery 使用 AJAX 加载每个选项卡的数据;这些选项卡使用队列一个接一个地加载。在每个选项卡中,都有包含 HTML 和 JavaScript 的“小部件”(对于每个选项卡加载,都有各种脚本标签)。
I am getting the 'slow script' error during the loading of the tabs. I know that IE hates when scripts don't return control to the browser. So, I was wondering if there was a way to 'return control' or sleep somehow, so IE can 'reset' it's slow script counter.
我在加载选项卡期间收到“慢速脚本”错误。我知道 IE 讨厌脚本不将控制权返回给浏览器。所以,我想知道是否有办法“返回控制”或以某种方式休眠,以便 IE 可以“重置”它的慢速脚本计数器。
采纳答案by Ron Harlev
Someone came up with an idea here
有人在这里提出了一个想法
Avoiding the 'Script taking too long' (all browsers have some form or another of this) message in browsers is relatively simple. You just have to make sure the browser knows you have not created an endless loop or recursion. And the easiest way to do is is to just give the browser a breather in between long running tasks.
So how would we go about this. Well the simplest solution is to just break up your task into mutliple smaller tasks with a setTimeout in between these tasks. The utility (see link) does just this
在浏览器中避免“脚本耗时过长”(所有浏览器都有某种形式)消息相对简单。您只需要确保浏览器知道您没有创建无限循环或递归。最简单的方法是让浏览器在长时间运行的任务之间喘口气。
那么我们将如何处理这个问题。那么最简单的解决方案就是将您的任务分解为多个较小的任务,并在这些任务之间设置一个 setTimeout。该实用程序(见链接)就是这样做的