JavaScript Timers with setTimeout and setInterval

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

15-Jan-07 00:00
This is a forum topic for discussing the article "JavaScript Timers with setTimeout and setInterval":

http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

In this tutorial we'll look at JavaScript's setTimeout(), clearTimeout(), setInterval() and clearInterval() methods, and show how to use them to set timers and create delayed actions.
03-Mar-10 03:54
Excellent explanation of timers and your examples are great.
Thank you.
03-Mar-10 16:34
@akeane: Thanks for your kind words. I'm glad you enjoyed the tutorial.

Cheers,
Matt

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
10-Apr-10 14:57
Another thing to talk about here with setInterval is setting a loop counter and clearing the interval when that loop count is hit.



var counter = 0
intervalId = 0;

function myLoopFunction()
{
intervalId = setInterval(function() {
//make this is the first thing you do in the set interval function
counter++;

//do you code for setInterval() and clearInterval under normal conditions here...

//okay, if we have tried for 5 minutes (30 x 10 seconds ), then lets stop trying because we did not reach the clearInterval under number means

//make this the last check in your set interval function
if ( counter > 30 ) {
clearInterval(polliFrameSourceIntervalId);
}

//end setInterval
} , 10000);



07-Dec-10 00:12
Very useful post, and the examples are just superb, thanks, it helped a lot!!

--
Guptas
09-Dec-10 19:22
@anupam: Thanks, glad you found it helpful

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
19-Jan-11 08:27
I Just want to thank you for such a great and simple to follow tutorial. I have looked at a lot over the past few weeks and I have got to say this is the best one I have seen for ages. Keep up the good work this has helped me heaps.
20-Jan-11 14:20
@NT_Jester: You're welcome - thanks for the kind words. Hope life is good up in the NT!

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
19-Aug-11 07:47
Great and detailed explanations, I took the time to create an account just to thank you as it helped debugging a JavaScript issue I had since a while.
23-Aug-11 22:41
@ecommy: Great stuff

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
08-Feb-12 08:16
Thank you for this post.
I was able to modify this for a music writing application.
I will link back.
13-Feb-12 04:10
@froopy: You're welcome - thanks for the link back

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
30-Apr-12 16:10
thank you for taking the time to create this clear and useful post!

 
New posts
Old posts

Follow Elated