Stop running this script

孤街醉人 提交于 2019-12-18 11:44:53

问题


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.

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.

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

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

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.


回答1:


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



来源:https://stackoverflow.com/questions/5667456/stop-running-this-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!