How to Reload Page after Specific Time (5 seconds) in JavaScript

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.

  • The delay time must be specified in milliseconds. If you want to execute code after 5 seconds, 5000 should be passed in the delay parameter.
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.

1 Comment

  1. Luqmaan Shaik Said...

Leave a reply

keyboard_double_arrow_up