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.

Well i use firefox daily and i use the setTimeout with some of my ajax and it works in IE, FF, safari, chrome, and opera just fine if used properly

example

var interval;
function myFunction(){
   // write the function below
   
   clearTimeout(interval);
   setTimeout('doSomethingElse()', 1000);
}

also may i ask what version of firefox are you using because I've used it on version 3.0 and above

Thanks for responding.

After receiving your response, I created a .htm page containing only the timeout code. It is working on XP and Vista clients, but my personal development machine is 2003 server (for selfish reasons), which now appears to be the only cause of the FF failure. I uploaded the .htm (http://www.nicsysco.com/testtimeout.htm) page to my production server and it works fine on the other platforms but FF is inconsistent on server 2003; working and then sometimes not working. IE is working fine.
BTW, I am using FF 3.6.

Do you have any information on FF and MS2003?

Thanks

Well i use firefox daily and i use the setTimeout with some of my ajax and it works in IE, FF, safari, chrome, and opera just fine if used properly

example

var interval;
function myFunction(){
   // write the function below
   
   clearTimeout(interval);
   setTimeout('doSomethingElse()', 1000);
}

also may i ask what version of firefox are you using because I've used it on version 3.0 and above

On MS2003 i don't have any information since i use windows XP, Vista, and Linux and my web server is Linux so i don't have any information on MS2003 but i can tell your htm page for this is working on my vista currently but with the MS2003 it actually might be the systems fault not the browser if you understand what i mean since software works in different was on different platforms you might want to test a couple other browser like safari, chrome, and opera and see how they work with your development but sorry i can be any more help then that a the moment i do not think anyways but if any thing comes to me I'll let you know sorry

You have been a great help, thank you. I googled Firefox and MS2003 and there seem to be problems with that combination, so I'll have to take that into consideration in the future. Your response put me on the right track.
Thanks once again.
Stay well.

On MS2003 i don't have any information since i use windows XP, Vista, and Linux and my web server is Linux so i don't have any information on MS2003 but i can tell your htm page for this is working on my vista currently but with the MS2003 it actually might be the systems fault not the browser if you understand what i mean since software works in different was on different platforms you might want to test a couple other browser like safari, chrome, and opera and see how they work with your development but sorry i can be any more help then that a the moment i do not think anyways but if any thing comes to me I'll let you know sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.