I have an inherently complicated page designed by an idot running a script on load that takes too much time and generates the Stop Script dialog box.
The page works fine on all tested browsers except IE6/7/8.
I would like to know if I can break up the script with settimeouts to avoid this error.
Something like: $(‘.level’).each(f(){settimeout(f(){script},1)});
Update: Yes of course I knew everyone would want to see code, but it’s big too. Perhaps this line will indicate the idea of what’s happening at the top level of the onload:
$('#thetable').find('tr.listing :checkbox').click(function(event) { ... });
where there are around 5700 dom nodes in #thetable in one of the more modest sets of search results.
I think the search on this selector $(‘#thetable’).find(‘tr.listing :checkbox’) is what is taking the time in IE.
There are a couple things you could do…
It sounds like your showing a result set in a table. In this case you may want to implement paging and have the script go back to the server for more results on the page change event. This will mean less DOM nodes to process, and should take care of the stop script problem.
Another approach you could try is giving your check boxes predictable ID’s and then doing a direct select such as $(“#thetable_checkbox_” + checkboxid) and then having a forloop iterate through the results, changing the checkboxid you are selecting on.
Here is some pseudocode as an example
Where your checkbox ID’s have been generated on with ID’s like thetable_checkbox_1 etc.
The approach you mentioned for breaking up the script with setTimeout will also work, but you need to avoid jQuery selectors that could take a long time. You can also set the timeout value to 0 since you want it to run as soon as the browser is ready. Setting the timeout to 0 yeilds to the browser and allows it to run any operations it has pending before returning to your script. If the script is long running you should display a modal loading dialog so that the page is only displayed to the user when it is ready.