By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

FAQ Topic - How do I make a 10 second delay?

P: n/a
FAQ Topic - How do I make a 10 second delay?

There is no built-in way to pause execution in javascript such
as a sleep function, but hosts usually provide a method of some
form. Web browsers are designed for event driven programming and
only provide the `` setTimeout '' and `` setInterval '' functions
to facilitate timed delays.

To call the function `` Snork() '', approx 10 seconds
after the function `` Moomin() '', you would do this:


Script execution is not stopped, and adding `` Snufkin() '' after the
setTimeout line would immediately execute the function `` Snufkin() ''
before `` Snork() ''

Achieving delays through running a loop of some sort for a
pre-defined period is a bad strategy, as that will tend to
put CPU use up to 100% and inhibit whatever was supposed to
be happening during the delay.

Other (less event driven) hosts have different wait functions,
such as `` WScript.Sleep() '' in the Windows Script Host.
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at
The FAQ workers are a group of volunteers.

Sep 1 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
JRS: In article <44***********************>, dated Fri,
1 Sep 2006 23:00:02 remote, seen in news:comp.lang.javascript, FAQ
server <ja********@dotinternet.beposted :
>FAQ Topic - How do I make a 10 second delay?
IMHO there should be a note that the delay before calling Snork will
generally exceed that called for by the second parameter, because of
implementation details. </FAQENTRY>

<URL: show the
effect; it averages at least 27 ms in IE4/Win98 and much less in newer
systems, and may well increase if the OS is busy. But, for clock-like
applications, the error should be corrected.

Will the FAQ actually be updated?
John Stockton, Surrey, UK. ? Turnpike v4.00 IE 4
<URL:>? JL/RC: FAQ of news:comp.lang.javascript
<URL: maths, dates, sources.
<URL:, FAQ items, links.
Sep 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.