From javascript I'm calling a web method. With IE, if I pass a huge parameter to that web method, an alert "Stop running this sciprt? A script on this page is causing internet explorer to run slowly" pops up.
Is it possible to handle the click on the "Yes" button, so that if the user decides to cancel the script execution I can run some alternative script (in this case, my "alternative" script consists in closing some progress bar I popup just before running the long time script).
I have seen many posts explaining how to prevent this alert from being displayed, but I don't want to stop the alert from being displayed: I just want to be able to handle the case in which the user decides to stop the script execution.
First, go to the Settings section and scroll down to Browsing. Next, check the box associated with Disable script debugging (Internet Explorer). Next, look down below and uncheck the box associated with Display a notification about every script error.
A script on this page may be busy or may have stopped responding. You have the choice of "Stop Script" or "Continue" buttons. Click the "Stop Script" button to stop the script from running. Stopping the script can prevent the browser from running out of memory or crashing.
You can resolve the Long Running Script error by using coding best practices, modularizing your scripts, and thoroughly testing code before deployment under as many different conditions as possible.
A: Script error messages tend to appear when one's browser is out of date. What happens is the website you are visiting contains a version of JavaScript (the programming language that allows for animation and interactivity on websites) that is newer than what is installed on your browser.
I've dealt with this before on an internal app where they didn't care how long it took the browser to crunch the numbers, they just didn't want to have to click the prompt.
The key is to break the work down into relatively predictable chunks of work (predictable in terms of CPU time) and run them on a setInterval like:
function doWork(begin, end) {
// Some chunk of what your worker function normally does from begin to end
if (actualEnd < end) // Nothing left to do
clearInterval(Interval);
}
var Interval = setInterval(doWork, 15);
This prevents the IE prompt from appearing (or Chrome from presenting the "Freeze" dialog). The next step is to add some code that lets the user skip it entirely; if the amount of work is known at the beginning, ask them right away. If not, start processing and after n chunks ask them if they'd like to do the cheaper function.
There are 2 other options for getting this much work done:
Finally, if you are doing this much work on demand, there are probably speed-up opportunities in the work you're performing - the data could be indexed beforehand on the server to make the calculations faster/simpler, things like that. But I don't know what you're calculating.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With