![]() |
| ||
| Is there a sleep/wait javascript function for firefox? I need to suspend processing in my script for a few seconds, and i am not sure how. Thanks, sj |
| ||
| Re: Is there a sleep/wait javascript function for firefox? There is no "sleep" or "wait" operator in JavaScript. You can set a timer, though, and when the timer expires, it will execute a function. setTimeout("alert('hello')",1250);
You could have it wait so many milliseconds, and then execute an empty procedure, I suppose. |
| ||
| Re: Is there a sleep/wait javascript function for firefox? What you usually do is what Tom has suggested, but you would invoke a call to the code that you want to execute after timeout. So if you had an algorithm like such: function myFunction(){
You would implement this with: function myFunction(){
This effective 'pauses' the execution of your code. |
| ||
| Re: Is there a sleep/wait javascript function for firefox? Just what i needed. Thanks guys, sj |
| ||
| Re: Is there a sleep/wait javascript function for firefox? This solution is not really a sleep. It effectively postpones the execution of function called by the setTimeout method, but javasctipy is asynchronous, so the execution of the commands following the setTimeout method will happend immediately after. After a couple of google queries I found the only solution to sleep was to execute this function: function pause(millis) Problem with this approach is when you need a few of shor sleeps one after another. In this case the only thing that happends is the cpu usage is gonna hit the roof and the script gets paused till the last pause is executed. |
| ||
| Re: Is there a sleep/wait javascript function for firefox? Thanks nemo5 for your input! I needed a way to cause a method to stop in its tracks so the calling method didn't think the currentl one was done yet, and this should do it. |
| ||
| Re: Is there a sleep/wait javascript function for firefox? The two approaches (do while, and dosomething/settimeout(dosomeelse)) are used in different situations. 1. do while You just want to pause, but are not expecting anything to happen in the browser while waiting (no document loading, no event). The javascript interpreter will be busy executing the while loop. (Check http://www.sean.co.uk/a/webdesign/javascriptdelay.shtm) 2. dosomething/settimeout(dosomeelse) If you want your code to wait for something to happen, like a dom node being created or loaded you have to resort to other tactics. Joseph Moore at http://40withegg.com/2007/1/5/a-non-...ript-wait-loop calls it a non-cpu intensive wait. Meaning the browser can still function and thus perform job that your code is waiting on. |
| All times are GMT -4. The time now is 3:58 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC