views:

506

answers:

3

I'm looking to automate the changing of images in a slideshow. I'd rather not install any 3rd party plugins if possible.

Thanks.

+17  A: 
window.setInterval(function(){
  /// call your function here
}, 5000);
Doug Neiner
beat me by half a minute!
John Boker
+1 You seriously answered this like a second or so after it was asked!? I call foul! :)
Jonathan Sampson
I smell inside job..
Anthony Forloney
Who says I can't refresh every 2 seconds :D
Doug Neiner
If I did plan an inside job, I would do it so my rep wouldn't cap after the first upvote :P
Doug Neiner
I wonder what happens when you reach your cap limit if someone tries to upvote you. Does that vote never reach your rep? I've never known.
Anthony Forloney
It still counts toward your individual tag stats, but no, you never again see the rep on your total rep score. Whats worse, is if you got 10 upvotes, but only one counted, and then someone downvotes, you still lose the 2 points. Oh well, par for the course!
Doug Neiner
I'll wait to +1 for your speedy answer to the question when your rep's not capped, in the meantime I will +1 your comment for being so informative to my question :)
Anthony Forloney
To the downvoter, do you have an easier way?
Doug Neiner
+5  A: 

you could register an interval on the page using setInterval, ie:

setInterval(function(){ 
    //code goes here that will be run every 5 seconds.    
}, 5000);
John Boker
setTimeout runs once only.
Jonathan Sampson
yeah i fixed it, trying to type too fast, knew it would be answered quickly :)
John Boker
Your opening suggestion still references setTimeout :)
Jonathan Sampson
well, thanks :) man it's late. need to stop trying to answer questions when tired.
John Boker
You could always call `setTimeout` again from within the function....that's the way I used to do it >.< I guess it can't be an anonymous function then. Unless there's some sort of call_self() function I'm unaware of.
Mark
@Mark Yup, that's how I do it when timing is not very critical, but a job needs to execute periodically.
HRJ
+3  A: 

Both setInterval and setTimeout can work for you (as @Doug Neiner and @John Boker wrote).
See here for some more explanation about both to see which suites you most and how to stop each of them.

Dror