Reload the page with JavaScript location.reload()

12/25/2021

Contents

In this article, you will learn how to reload the page with JavaScript location.reload().

What is location.reload()?

To reload the page in JavaScript, use the location.reload().
The location.reload () is a method that allows you to reload the browser and reload the URL of the currently open page.

The syntax is as follows.

location.reload()

Reload the page by clicking the button

Use the click event of addEventListener.

HTML

<button class="btn" type="button">Reload</button>

JavaScript

document.querySelector('.btn').addEventListener('click', ()=>{
    location.reload();
}, false);

Reload the page after a certain period of time with setTimeout

Reloads the page after the number of seconds specified in setTimeout().
Specify the time in milliseconds as the second argument.

JavaScript

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

Reload the page at regular intervals with setInterval

Reload the page at regular time intervals with setInterval().
Specify the time interval in milliseconds as the second argument.

JavaScript

setInterval(() => {
    location.reload();
}, 5000);