Block "stop execution of this message script"

I have an array with 2000 arrays, each of which has 2000 values ​​(to accommodate a 2000x2000 image) in javascript in HTA. I have this code to check how many "blue" values ​​are in the array (array name is image ):

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

The problem is that it shows a message that says something like "Stop execution of this script? Script on this page slows down Internet Explorer. If it continues, your computer may not respond." (I’m not sure about the exact words because my computer is in French), and then if I click β€œno”, it does alert(bluePixels) as it should, but if I click β€œyes”, it’s not . How to block this message? (I know that there are workarounds, for example, when the user first says no, but I want a real solution)

+1
javascript arrays
Jan 25 '15 at 12:01
source share
3 answers

For IE versions 4 through 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 does not exist, create it. In this vein, create a DWORD value called MaxScriptStatements and set it to 0xFFFFFFFF (don't worry if the value changes automatically when you click OK, that's fine).

You can program JavaScript for 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"); 
+1
May 6 '16 at 9:50
source share

It looks like you have an answer here

From the answer: "The only way to solve the problem for all users who can view your page is to break the number of iterations that your loop uses with timers or reorganize your code so that it does not process so many instructions."

Thus, the first approach can be achieved using a timeout for each such large iteration.

+1
Jan 25 '15 at 12:04
source share

You need to divide 2000x2000 for the loop into smaller pieces of code, such as threads or processes, so the maximum browser runtime is not exhausted. Here, an array of images is analyzed one line 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 split in 2000 processes instead of 1.

+1
Jan 25 '15 at 12:29
source share



All Articles