javascript - Issue with setTimeOut and non-response script in IE8 -
i getting issue large amount of processing causing non-responsive script error in ie8 (and no, cannot make users use better browser).
i read should possible split tasks , cede control browser in between different parts of validation. decided make simple example based on code found figure out breaking points are. real code doing lots of jquery validationengine processing.
i tried use jsfiddle can't jsfiddle run in ie8. bummer. so, i'll have share inline here.
when first load it, seems work fine. push button , both functions finish without problem. however, subsequent pushes causes unresponsive script error. i've played around number of loops in simulated work function. more 1.25 million loops , dies unresponsive script.
shouldn't separate calls onclick start non-responsive counter anew? missing here?
<html> <head> <script> var progress = null; var gobutton = null; window.onload = function() { progress = document.getelementbyid("progress"); gobutton = document.getelementbyid("gobutton"); } function runlongscript(){ // clear status progress.value = ""; gobutton.disabled=true; var tasks = [function1, function2]; multistep(tasks,null,function() {gobutton.disabled=false;}); } function function1() { var result = 0; var = 1250000; (;i>0; i--) { result = result + 1; } progress.value = progress.value + "f1 end "; } function function2() { var result = 0; var = 1250000; (;i>0; i--) { result = result + 1; } progress.value = progress.value + "f2 end"; } function multistep(tasks, args, callback){ var tasksclone = tasks.slice(0); //clone array settimeout(function(){ //execute next task var task = tasksclone.shift(); task.apply(null, args || []); //determine if there's more if (tasksclone.length > 0){ settimeout(function () { multistep(tasksclone, args, callback); }, 100); } else { callback(); } }, 100); } </script> </head> <body> <p><input type="button" id="gobutton" onclick="runlongscript();" value="run long script" /></p> <input type="text" id="progress" /> </body> </html>
you're never calling cleartimeout()
remove 1 running when button has been pressed already. add if statement before start settimeout
, check see if 1 running, clear if is, , continue. here's link should if have questions: https://developer.mozilla.org/en-us/docs/web/api/window.cleartimeout
Comments
Post a Comment