Reputation: 134
I'm using the firebug console to test a script... Right at the start of my script i have an option on the number of times i want the script to run!
My problem is:
notes:
example of code:
var x = prompt("How many times should this script be runned?");
alert("It will be runned " + x + " times then!");
function doThis() {
setTimeout(function(){
...;
++n;
--x;
action();
},65000);
}
function doThat() {
setTimeout(function(){
...;
++n;
--x;
action();
},65000);
}
function action() {
if(x>0) {
if(...) {
if(n<6){
doThis();
}
} else {
if(n<6){
doThat();
}
}
} else {
alert("The Script has ended!");
}
action();
Upvotes: 0
Views: 1518
Reputation: 707766
Yes, most browsers today have a time limit on how long a script can run before it returns control back to the user. This is to prevent an errant or deviant script from "hanging" that browser window.
One can typically work around it by putting a smaller timer between runs. This gives the browser a chance to service it's event loop and prevents the prompt about running too long.
I shoot for a chunk of work taking no longer than 10 seconds or so and that is way below the threshold of all browsers. Here are some previous answers about breaking your work into chunks separated by a short timer interval so things can run basically forever.
Best way to iterate over an array without blocking the UI
Avoiding "Unresponsive Script" message in a foreach loop
Best way to iterate over an array without blocking the UI
Upvotes: 1