Can I set a recurring timer so that I check certain conditions and do something periodically?
4 Answers
Accepted Answer
setInterval ( "doSomething()", 5000 ); // runs every 5 seconds function doSomething ( ) { // (do something here) }
Hey Peter,
You can use Javascript's setInterval for that. An example would be:
setInterval ( "doSomething()", 5000 ); function doSomething ( ) { // (do something here) }There's more info about setTimeout and setInterval here
Hey Dan -- we posted almost the exact same example at the exact same time. (But mine's better, because I added a comment :)
Actually , setInterval is a little cleaner because you don't have to keep resetting it.
Oops, yeah, Mark's right. I pasted the wrong example. LOL
setInterval is the way to go, I'll update my previous comment so the example matches what the comment says. :)
Your Answer
Think you can help? Login to answer this question!