Categories
JavaScript Answers

How to auto refresh page every 30 seconds with JavaScript?

Spread the love

Sometimes, we want to auto refresh page every 30 seconds with JavaScript.

In this article, we’ll look at how to auto refresh page every 30 seconds with JavaScript.

How to auto refresh page every 30 seconds with JavaScript?

To auto refresh page every 30 seconds with JavaScript, we call setTimeout with a callback that calls location.reload.

For instance, we write

window.setTimeout(() => {
  window.location.reload();
}, 30000);

to call setTimeout with a callback that calls location.reload after 30000 milliseconds or 30 seconds.

Conclusion

To auto refresh page every 30 seconds with JavaScript, we call setTimeout with a callback that calls location.reload.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *