By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 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:

Moomin()
setTimeout('Snork()',10000)

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.

http://msdn.microsoft.com/workshop/a...setTimeout.asp

http://docs.sun.com/source/816-6408-...ow.htm#1203758

http://en.wikipedia.org/wiki/Event-driven_programming
===
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
Share this Question
Share on Google+
1 Reply


P: n/a
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?
setTimeout('Snork()',10000)
<FAQENTRY>
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.