PDA

View Full Version : Doing Javascript Function ever x number of seconds


Yaggles
11-04-2005, 03:44 AM
I would like to have it execute a javascript function every X number of seconds, but I don't know how. My first inclination was to use META tags, but I don't see that working. Is there a way to do a count down in javascript and then execute the function?

gph
11-04-2005, 03:54 AM
http://www.w3schools.com/js/js_timing.asp

dreamingdigital
11-04-2005, 04:20 AM
If you want to call a function every X number of miliseconds you want to use setInterval

If you want to call a function once after X number of miliseconds you want to use setTimeout

examples:

setInterval("my_function()",2000); // will call my_function() every 2000 miliseconds or 2seconds

setTimeout("my_function()",4000); // will call my_function() every 4000 miliseconds or 4seconds

Yaggles
11-04-2005, 08:26 AM
Thanks! I think i'll use the setInterval one because that is more of what I need. Thanks both of you, however!