Stop running this script

Rocket Hazmat picture Rocket Hazmat · Apr 14, 2011 · Viewed 16.7k times · Source

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.

Answer

Ron Harlev picture Ron Harlev · Apr 14, 2011

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