How to Load iFrame Every X Seconds

To reload an iframe every X-seconds, you simply need to use the setInterval() function in JavaScript, with a handy bit of script.

let iframe = document.getElementById("frame1");let delay = 1000 * 10; //10 * 1000 = 10 secondslet ival = setInterval(function() { iframe.src = iframe.src;}, delay);

In the above code, we:

  1. Create a reference to the iframe (<iframe id=”frame1″></iframe>).
  2. Create the delay. Time is tracked in milliseconds (1000 = 1 second).
  3. Start the interval, and store a reference to it.

The iframe will be reloaded every 10 seconds. If we want to stop the reloading, we do this:

clearInterval( ival );

JavaScript returns an integer from setInterval(), which is a unique identifier to that call of setInterval().