View Full Version : Js delay function

04-08-2003, 04:16 PM
I need a function in js that delay my page before loading for few seconds.
What's function do I need?

04-08-2003, 04:49 PM
There is no *synchronous* delay or wait functionality in javascript - but you could try to do something like this:
function fnDelay(iMs){ // iMs=[number TimeInMilliSeconds]
iStart=new Date;
while(new Date-iStart<iMs);
}And call that when you need the delay - but I wouldn't be surprised if you got a message that told you that execution of that script might slow the computer down. You usually get those when you try to do potentially nonterminal loops, or loops that will take too much time to execute.

There is of course the asynchronous setTimeout that you can use, but then your script execution will continue while waiting.