How to prevent "Stop running this Script" in browsers?

Rita

I have an ASP.NET MVC page that has JQuery Editable Datatable that has 14 columns. I have a button (Apply No Findings)to do Client side calcultions snd apply for all Rows in that table.

When we click on this button, after applying calculations for every 4 Rows, it is displaying this "Stop Running Script" Message.

I verified the settings. In the Internet Options, Advanced tab, "Disable Script debugging(Internet Explorer)" option is Checked. And "Display a Notification about Script Error" is Unchecked.

I am using Internet Explorer 8. I Now it does not happen on IE9. But this being the server, we cannot upgrade to IE9.

I did the Research 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 had this isse and any suggestions are highly appreciated.

This is actual code that is throwing the 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();

By referring sample code in Example(2), I changed the code as below and I am still getting the Script message:

//This function is to avoid Script Running Message

  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?

Khanh TO

The problem is javascript is single-threaded, so if there is a function that takes too long to complete, this function could cause the UI not responding. Therefore, the browser will warn the user about long running script by displaying the message: "Stop running this script". The solutions to this problem are:

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

Example code pattern:

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 solution you take in your Example(2) is correct, but there is a problem in your code. That's the setTimeout does not run. Try changing your code like this:

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, [])         
       }    
    };   
  };

Modify your function ApplyNoFindings(), try this:

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

instead of:

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to prevent "Stop running this Script" in browsers?

From Dev

How to stop running script by using different script

From Dev

How to stop a running script which calls a infinite loop

From Dev

"Stop running this script?" -- is this legit?

From Dev

How to prevent different browsers rendering fonts differently?

From Dev

How to prevent bare windows in Firefox and related browsers?

From Dev

When do browsers send referrers? How to prevent this?

From Dev

how to prevent browsers authentication dialog angularjs

From Dev

How to prevent default behavior when middle click on a link (browsers' extensions)

From Dev

How to prevent background scrolling when Bootstrap 3 modal open on mobile browsers?

From Dev

How can I reliably prevent my local IP address leaking in the web browsers?

From Dev

How to prevent background scrolling when Bootstrap 3 modal open on mobile browsers?

From Dev

Prevent user from copying text on mobile browsers

From Dev

Prevent autohide of address bar on mobile browsers

From Dev

Prevent Browsers back key after logging in

From Dev

jQuery mobile stop running the script in the current page used after moving to the next page

From Dev

How Browsers Work of modern web browsers

From Dev

How is "<" in HTML handled by browsers?

From Dev

How to Manage Sessions with browsers

From Dev

How is "<" in HTML handled by browsers?

From Dev

How browsers identify a video?

From Dev

Prevent browsers moving SVG elements around page breaks

From Dev

Prevent a video background from being downloaded on mobile browsers

From Dev

JQuery - Prevent browsers to scroll up after remove row (TR)

From Dev

Prevent software and browsers from recognizing my laptop as tablet

From Dev

Prevent a video background from being downloaded on mobile browsers

From Dev

Can the *ngIf directive prevent that my adminpage is sent to the browsers of unauthorized users?

From Dev

How is CSS/HTML Rendered In Browsers?

From Dev

How to block unknown browsers in .htaccess?

Related Related

  1. 1

    How to prevent "Stop running this Script" in browsers?

  2. 2

    How to stop running script by using different script

  3. 3

    How to stop a running script which calls a infinite loop

  4. 4

    "Stop running this script?" -- is this legit?

  5. 5

    How to prevent different browsers rendering fonts differently?

  6. 6

    How to prevent bare windows in Firefox and related browsers?

  7. 7

    When do browsers send referrers? How to prevent this?

  8. 8

    how to prevent browsers authentication dialog angularjs

  9. 9

    How to prevent default behavior when middle click on a link (browsers' extensions)

  10. 10

    How to prevent background scrolling when Bootstrap 3 modal open on mobile browsers?

  11. 11

    How can I reliably prevent my local IP address leaking in the web browsers?

  12. 12

    How to prevent background scrolling when Bootstrap 3 modal open on mobile browsers?

  13. 13

    Prevent user from copying text on mobile browsers

  14. 14

    Prevent autohide of address bar on mobile browsers

  15. 15

    Prevent Browsers back key after logging in

  16. 16

    jQuery mobile stop running the script in the current page used after moving to the next page

  17. 17

    How Browsers Work of modern web browsers

  18. 18

    How is "<" in HTML handled by browsers?

  19. 19

    How to Manage Sessions with browsers

  20. 20

    How is "<" in HTML handled by browsers?

  21. 21

    How browsers identify a video?

  22. 22

    Prevent browsers moving SVG elements around page breaks

  23. 23

    Prevent a video background from being downloaded on mobile browsers

  24. 24

    JQuery - Prevent browsers to scroll up after remove row (TR)

  25. 25

    Prevent software and browsers from recognizing my laptop as tablet

  26. 26

    Prevent a video background from being downloaded on mobile browsers

  27. 27

    Can the *ngIf directive prevent that my adminpage is sent to the browsers of unauthorized users?

  28. 28

    How is CSS/HTML Rendered In Browsers?

  29. 29

    How to block unknown browsers in .htaccess?

HotTag

Archive