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.
Advertising Disclosure: I am compensated for purchases made through affiliate links. Click here for details.
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.
Posted by: Josh Rowe
Created: September 03, 2022
Created: September 03, 2022
Comments
There are no comments yet. Start the conversation!