Reload the page with JavaScript location.reload()

Web Design & Web Development
Sponsored links

In this article, I will introduce 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()
Sponsored links

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);
Sponsored links

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);
Sponsored links

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);