|
Prev: FAQ Topic - How do I get a perl/asp/php variable into client-side js? (2008-05-03)
Next: Really annoying flickering
From: FAQ server on 4 May 2008 19:00 ----------------------------------------------------------------------- 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. The delay before calling Snork may exceed the second parameter to ` setTimeout ` and ` setInterval ` due to implementation differences among browsers. 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://msdn2.microsoft.com/en-us/library/ms536753.aspx http://docs.sun.com/source/816-6408-10/window.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://jibbering.com/faq/index.html. The FAQ workers are a group of volunteers. The sendings of these daily posts are proficiently hosted by http://www.pair.com. |