-2

How call JavaScript functions in time interval. I want call a function with time interval how can I done that

M Kattody
  • 1
  • 1

1 Answers1

0

If you want to call it after a certain time interval you can do something like this (this will do it after 3 seconds);

setInterval(MyFunc, 3000);

setInterval() has a signature that is a function being the first parameter and the interval in milliseconds as the second parameter (thus the amount of seconds is equal to 3000/1000 as there are 1000 milliseconds per second). SetInterval will also call that function over and over again every 3 seconds! So make sure you want it to!

For example if you wanted to show an alert you could do:

setInterval(function() { alert("Hello World") }, 3000);

If you want it to run only once just replace setInterval with setTimeout which will just run it once after the time given (again in milliseconds).