Location: replace() method
The replace() method of the Location
interface replaces the current resource with the one at the provided URL. The difference
from the assign() method is that after using
replace() the current page will not be saved in session History,
meaning the user won't be able to use the back button to navigate to it.
Syntax
js
replace(url)
Parameters
url-
A string containing the URL of the page to navigate to.
Exceptions
SyntaxErrorDOMException-
Thrown if the provided
urlparameter is not a valid URL.
Return value
None (undefined).
Examples
js
// Navigate to the Location.reload article by replacing this page
window.location.replace(
"https://developer.mozilla.org/en-US/docs/Web/API/Location.reload",
);
Specifications
| Specification |
|---|
| HTML Standard # dom-location-replace-dev |
Browser compatibility
| desktop | mobile | server | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
replace | ||||||||||||
See also
- The
Locationinterface it belongs to. -
Similar methods:
Location.assign()andLocation.reload().