How to avoid the Unresponsive Script popup in Firefox with long running Javascript?

后端 未结 5 866
心在旅途
心在旅途 2021-01-02 05:18

I want to benchmark some Javascript code in the browser, but it may trigger Firefox\'s \"Warning: Unresponsive script\" popup. This allows the user to click \"Stop script\"

相关标签:
5条回答
  • 2021-01-02 05:23

    You have to break up long actions into smaller ones and perform them in turns. This will also allow a better progress indication.

    http://www.sonofsofaman.com/hobbies/code/settimeout.asp

    0 讨论(0)
  • 2021-01-02 05:36

    The below code solved that problem for me...

    <script type="text/javascript">
       function downloadJSAtOnload() {
       var element = document.createElement("script");
       element.src = "deferredfunctions.js";
       document.body.appendChild(element);
       }
       if (window.addEventListener)
       window.addEventListener("load", downloadJSAtOnload, false);
       else if (window.attachEvent)
       window.attachEvent("onload", downloadJSAtOnload);
       else window.onload = downloadJSAtOnload;
    </script>
    
    0 讨论(0)
  • 2021-01-02 05:39

    You can use the script from this question to break processing long lists into smaller chunks:

    How can I give control back (briefly) to the browser during intensive JavaScript processing?

    0 讨论(0)
  • 2021-01-02 05:41

    See in blog of Nicholas C. Zakas What determines that a script is long-running? (at 2009/01/05)

    Speed up your JavaScript, Part 1 http://www.nczonline.net/blog/2009/01/13/speed-up-your-javascript-part-1/

    there are the reasons and the ways how to avoid the dialog

    0 讨论(0)
  • 2021-01-02 05:45

    In firefox's address bar type about:config

    You want to change dom.max_script_run_time to be large enough for your scripts to run.

    0 讨论(0)
提交回复
热议问题