The Location
.replace()
method 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.
If the assignment can't happen because of a security violation, a DOMException
of the SECURITY_ERROR
type is thrown. This happens if the origin of the script calling the method is different from the origin of the page originally described by the Location
object, mostly when the script is hosted on a different domain.
If the provided URL is not valid, a DOMException
of the SYNTAX_ERROR
type is thrown.
object.replace(url);
DOMString
containing the URL of the page to navigate to.// Navigate to the Location.reload article by replacing this page document.location.replace('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'Location.replace()' in that specification. | Living Standard | No change from HTML5. |
HTML5 The definition of 'Location.replace()' in that specification. | Recommendation | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | Yes | Yes | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Location
interface it belongs to.Location.assign()
and Location.reload()
.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/location/replace