468,458 Members | 1,919 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,458 developers. It's quick & easy.

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

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 http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

Sep 1 '06 #1
1 5665
JRS: In article <44***********************@news.sunsite.dk>, 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:http://www.merlyn.demon.co.uk/js-date0.htm#TaIwill 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. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jonathan Mark | last post: by
4 posts views Thread by FAQ server | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.