Location Reload: How to Reload a Page in JavaScript
This tutorial will teach you how to reload a page with the Location.reload() method, available in JavaScript's built-in window.location object and Location API.
The Syntax
Location.reload(forceReload);
forceReload is an optional boolean argument, determining whether or not the reloaded page will contain fresh content or will contain a cached version from the browser.
A value of true reloads a fresh page from the server:
window.location.reload(true);
A value of false, or an omitted forceReload parameter, will reload a version of the page cached by the browser:
window.location.reload(false);
window.location.reload();
Assign to an HTML Element with an onClick Event
You can bind this event to any HTML element on a page using an onClick event handler:
<button type="button" onClick="window.location.reload();">Refresh</button>
Browser Support
The Location.reload() method in JavaScript is widely available in all modern browsers.
Written by: J. Rowe, Web Developer
Created: September 03, 2022
JavaScript