Skip to content Skip to sidebar Skip to footer

Block "stop Execution Of This Script" Message

I have an array with 2000 arrays which each have 2000 values (to stock a 2000x2000 image) in javascript in an HTA. I have this code to test how many 'blue' values there are in the

Solution 1:

For IE versions 4 to 8, you can do this in the registry. Open the following key in Regedit: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles. If this key doesn't exist, create it. In this key, create a DWORD value called MaxScriptStatements and give it the value 0xFFFFFFFF (don't worry if the value changes automatically when you click on OK, that's normal).

You can program JavaScript to do this automatically:

var ws = new ActiveXObject("WScript.Shell");
ws.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Styles\\","");
ws.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Styles\\MaxScriptStatements",1107296255,"REG_DWORD");

Solution 2:

Seems like you have an answer here

From the answer: "The only way to solve the problem for all users that might be viewing your page is to break up the number of iterations your loop performs using timers, or refactor your code so that it doesn't need to process as many instructions."

So the first approach can be attained using a timeout for each such large iteration.


Solution 3:

You need to split the 2000x2000 for-loop's up in smaller pieces of code, eg threads or processes, so the browsers maximum execution time not is becoming exhausted. Here the image array is parsed for one row at a time, controlled by a timer :

var bluePixels = 0,
    timer,
    i = 0;

function countBluePixels() {
    for (var j = 0; j < image[i].length; j++){
        if (image[i][j] == "blue") {
            bluePixels = bluePixels + 1;
        }
    }
    i=i+1;
    if (i>image.length) {
        clearInterval(timer);
        alert(bluePixels);
    }
}

timer = window.setInterval(countBluePixels, 0);

The code is the same, just splitted up in 2000 processes instead of 1.


Post a Comment for "Block "stop Execution Of This Script" Message"