The JavaScript setTimeout() method sets a timer to execute a function or specific code after a predefined time. If you want to refresh the page automatically after some specific time, the setTimeout() method is useful to do it in JavaScript. The location.reload() method helps to reload current URL and refresh the web page. Use location.reload() method in setTimeout() to reload page after specific seconds using JavaScript.
The following code snippet reloads page after 5 seconds and the web page will refresh automatically after 5 seconds in JavaScript.
setTimeout(function(){
window.location.reload();
}, 5000);
This example code sets 5 seconds to reload the page, you can set the time as per your needs.
Life and time saver content! Thanks 🙂