Welcome to WebmasterWorld Guest from 54.158.36.59

Forum Moderators: phranque

Message Too Old, No Replies

Need Java script delay code

How to add timer to any script...

     
8:18 pm on Jan 13, 2001 (gmt 0)

10+ Year Member



Is there a one line command that says "pause for this amount of time" in Javascript?

As you can tell, I know very little.

I did find some timers, but they were complete routines... and when I tried to "plug them in" into some existing scripts I have... I seem to have problems with subroutines inside of subroutines... or one function inside of another.

So... I am looking for a one line command that says "delay this many seconds before going to the next command."

Thanks,

Brett

8:54 pm on Jan 13, 2001 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You probably can use setTimeout(code,delay) [developer.irt.org]

However, this doesn't work exactly the way you described -- that is, it doesn't simply pause for a set period while going through a series of JavaScript commands.

Rather, whatever the "code" string is -- usually the name of a function defined earlier in the code -- JavaScript will delay the execution of that code for the amount of time specified by "delay" (in milliseconds).

Nevertheless, other commands that follow the setTimeout() line will continue to execute, so the effect is not the same as "don't do anything for xxx milliseconds".

9:06 pm on Jan 13, 2001 (gmt 0)

10+ Year Member



I am finding out that there is no pause or sleep command in javascript.

I was hoping there was a way to:

execute statement1
count to 10000 (i.e. 10 seconds)
execute statement2

-Brett

 

Featured Threads

Hot Threads This Week

Hot Threads This Month