Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle the "a script on this page is causing internet explorer to run slowly" alert?

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.

like image 323
pierre Avatar asked Apr 18 '11 08:04

pierre


People also ask

How do you stop a slow running script on Internet Explorer?

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.

How do I stop scripts from running on my computer?

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.

How do I fix a long running script problem?

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.

Why do I keep getting a script error message on my computer?

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.


1 Answers

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:

  1. Look ahead as to how much work there is to be done, and if it's a lot, pass it to the server (this unfortunately means writing your JS again on the server; of course, you could use a server engine that runs Javascript to save yourself some coding).
  2. Use background workers from Google Gears/HTML5

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.

like image 59
Chris Moschini Avatar answered Oct 27 '22 00:10

Chris Moschini