setTimeout works in Opera, but not in other browsers
I hit the dead end with this one, scratching my head for half a day already. The problem is quite strange, if you'd care to look at my source code: www.modwebsolutions.com/test2 (warning: not optimized yet, migh开发者_运维知识库t lock browser for a few seconds). Problem is, that sequence of setTimeouts works ok in Opera, but in other browsers only first one is executed and then execution of the script stops. Exerpt from my code:
var a1=setTimeout(drawVertical([arguments]),1000);
var b1=setTimeout(drawVertical([arguments]),1000);
var c1=setTimeout(drawVertical([arguments]),1000);
var d1=setTimeout(drawVertical([arguments)],1000);
Tried everything, enclosing function in quotes, looking for other syntax errors, nothing helped. And the strange thing is as I mentioned - everything works ok in Opera. UPDATE: also works in Chrome, and that makes it even more confusing...
UPDATE2: same example without timeout, works just fine (though slow): www.modwebsolutions.com/test
You should pass the parameters for you function after the function and timeout. Have a look at the documentation
var a1 = setTimeout(drawVertical, 1000, [arguments]);
What you have done here is called a function before setting the timeout. Immediately when the code sees drawVertical([arguments])
, it is going to call that function. The return value of that function is what you are passing as your first argument into setTimeout
, so unless drawVertical
returns a function, this won't work.
So you could get this to work by giving setTimeout
a function to call:
var args = arguments;
var a1=setTimeout(function() { drawVertical([args]); },1000);
...
EDIT: I set the outer arguments
to an args
variable, since the arguments
would be different in the inner function.
精彩评论