As many before me, I suppose, I have trouble with setTimeout() in FireFox. Oddly, I have no problems with IE.
If I use
setTimeout(loadnav1(),2000)
, FF fires loadnav1() immediately and try-catch complains about loadnav1() not being in quotations.
If I use
setTimeout('loadnav1()',2000)
, IE works fine, but FF does nothing.
Can anyone tell me why the code below does not work in FF? I put the try-catch in there to be sure that I am not encountering other problems. IE works perfectly, FF does nothing.
try{
var ntime=2000
var tf=function(){setTimeout(function(){loadnav1()},ntime);}
var tf2=new tf();
//this line of code fires loadnav1() a second time in IE, but even
//uncommented, FF does nothing.
//tf.apply(tf2)
}
catch(e){alert(e)}
function loadnav1()
{
alert(777)
}
Your sample code
function myFunction(){
doSomething();
setTimeout(function(){doSomethingElse();}, 500);
}
is also ignored by FF.
Any help would be appreciated.
Thanks
What you usually do is what Tom has suggested, but you would invoke a call to the code that you want to execute after timeout.
So if you had an algorithm like such:
function myFunction(){ doSomething(); wait(500); doSomethingElse(); }
You would implement this with:
function myFunction(){ doSomething(); setTimeout(function(){doSomethingElse();}, 500); }
This effective 'pauses' the execution of your code.