Skip to content

Auto refresh current page with regular intervals using JS

Last updated on June 6, 2022

To refresh or reload the active or current pages using JavaScript, you can use the location.reload() ,and setTimeout() methods.

The reload() method does the same as the reload button in your browser.

setTimeout() method calls to evaluate an expression after a specified number of milliseconds.

By default, the reload() method reloads the page from the cache, but you can force it to reload the page from the server by setting the forceGet parameter to true: location.reload(true).

Example script to Auto-refresh current page

Source code of a sample HTML page that reloads the page with 3 seconds regular intervals.

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
    <h1>Hello, world!</h1>
	   },3000); // 3000 milliseconds means 3 seconds.
0 0 votes
Article Rating
Notify of

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments