How to prevent "Stop running Script" in browsers?

I have an ASP.NET MVC page with jQuery Editable Datatable that has 14 columns. I have a (Apply No Findings) button to do snd client side calculations for all rows in this table.

When we click this button, after applying the calculations, for every 4 lines this "Stop Running Script" message is displayed.

I checked the settings. On the "Internet Options" tab, the "Advanced" tab, the option "Disable Script Debugging (Internet Explorer)" is checked. And "Display Notification of Script Error" is not marked.

I am using Internet Explorer 8. Now this does not happen in IE9. But this is a server, we cannot switch to IE9.

I researched and tried these two options, and nothing worked.

Example (1): http://www.codeproject.com/Tips/406739/Preventing-Stop-running-this-script-in-Browsers

Example (2): http://www.picnet.com.au/blogs/guido/post/2010/03/04/how-to-prevent-stop-running-this-script-message-in-browsers/

Anyone has this isse and any suggestions are highly appreciated.

This is the actual code that displays the message Script Message:

for(i < iTotalRecords;i++) { var row = oTableAuditLines.fnGetData(i); oTableAuditLines.fnUpdate("NF",i,1); UndoHCPCS(row,i); UndoHCPCSModCodes(row,i); UndoLineUnitCount(row,i); oTableAuditLines.fnUpdate("", i, 6); //Reset Denial Reason Code UndoNonCoveredCharges(row,i); CalculateAmountPaidAtLine(row,i); CalculateEstimatedRecoveryAmountAtLine(row,i); } UpdateSummaryLine(); UpdateSummaryLineReasonCode(); 

Inverting the sample code example in example (2), I changed the code as shown below, and I still get the Script message:

// This Function Avoids Script Run

  RepeatingOperation = function(op, yieldEveryIteration) { var count = 0; var instance = this; this.step = function(args) { if (++count >= yieldEveryIteration) { count = 0; setTimeout(function() { op(args); }, 1, []) return; } op(args); }; }; function ApplyNoFindings() { var i = 0; var ro = new RepeatingOperation(function() { var row = oTableAuditLines.fnGetData(i); oTableAuditLines.fnUpdate("NF",i,1); UndoHCPCS(row,i); UndoHCPCSModCodes(row,i); UndoLineUnitCount(row,i); oTableAuditLines.fnUpdate("", i, 6); //Reset Denial Reason Code UndoNonCoveredCharges(row,i); CalculateAmountPaidAtLine(row,i); CalculateEstimatedRecoveryAmountAtLine(row,i); if (++i < iTotalRecords) { ro.step(); } else { UpdateSummaryLine(); UpdateSummaryLineReasonCode(); } }, 100); ro.step(); 

}

What am I doing wrong here?

+7
javascript jquery asp.net-mvc asp.net-mvc-3
source share
3 answers

The problem is that javascript is single-threaded, so if there is a function that takes too long to complete , this function can cause the user interface to not respond. Therefore, the browser will warn the user about the script running for a long time by displaying the message: "Stop running the script . " Solutions to this problem:

  • Optimize your code so that the function does not take much time.
  • Use setTimeout to break function execution into many parts that are short enough.

Code example:

 var array = []; //assume that this is a very big array var divideInto = 4; var chunkSize = rowCount/divideInto; var iteration = 0; setTimeout(function doStuff(){ var base = chunkSize * iteration; var To = Math.min(base+chunkSize,array.length); while (base < To ){ //process array[base] base++; } iteration++; if (iteration < divideInto) setTimeout(doStuff,0); //schedule for next phase },0); 

The decision you make in your example (2) is correct, but there are problems in your code. That setTimeout is not working . Try changing your code as follows:

 RepeatingOperation = function(op, yieldEveryIteration) { var count = 0; var instance = this; this.step = function(args) { op(args); if (++count <= yieldEveryIteration) { setTimeout(function() { instance.step(args); }, 1, []) } }; }; 

Change your function ApplyNoFindings() , try the following:

 if (++i > iTotalRecords) { UpdateSummaryLine(); UpdateSummaryLineReasonCode(); } 

instead:

 if (++i < iTotalRecords) { ro.step(); } else { UpdateSummaryLine(); UpdateSummaryLineReasonCode(); } 

Note: not tested, just give you an idea of ​​how it should work.

+11
source share

Despite the already accepted answer, I want to post here general information for developers who will have this problem:

At this link you can find information on how to fix this from the user side http://support.microsoft.com/kb/175500 - the user can add one registry key.

You can also find there information about when the message "Running slow" appears:

By default, the key does not exist. If no key has been added, the default threshold for the timeout dialog is 5,000,000 statements for Internet Explorer 4 and later.

As you can see, the slowness measured in javascript statements is out of time.

+4
source share

You can also consider HTML 5 workers

A web worker is JavaScript running in the background without affecting page performance. When scripts are executed on an HTML page, the page stops responding until the script completes. A web worker is JavaScript that runs in the background, independent of other scripts, without affecting page performance.

Creating a new worker is simple. All you have to do is call the Worker () constructor, specifying the URI for the script to execute in the workflow, set the corresponding event handler function for the Worker.onmessage property.

 var myWorker = new Worker("my_task.js"); myWorker.onmessage = function (oEvent) { console.log("Called back by the worker!\n"); }; 

Alternatively, you can use addEventListener ():

 var myWorker = new Worker("my_task.js"); myWorker.addEventListener("message", function (oEvent) { console.log("Called back by the worker!\n"); }, false); myWorker.postMessage(""); // start the worker. 

You can see more information at: https://developer.mozilla.org/en-US/docs/Web/Guide/Performance/Using_web_workers

0
source share

All Articles