web api instance method
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.
Not to be confused with the String method replace().
Syntax
replace(url)
Parameters
url- : A string or any other object with a stringifier, such as a
URLobject, containing the URL of the page to navigate to.
- : A string or any other object with a stringifier, such as a
Exceptions
SecurityErrorDOMException- : Browsers throttle navigations and may throw this error, generate a warning, or ignore the call if it’s called too frequently.
SyntaxErrorDOMException- : Thrown if the provided
urlparameter is not a valid URL.
- : Thrown if the provided
Return value
None (undefined).
Examples
// 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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.