Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Location.replace()

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

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.

Syntax

object.replace(url);

Parameters

url
Is a DOMString containing the URL of the page to navigate to.

Examples

// Navigate to the Location.reload article by replacing this page
document.location.replace('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');

Specifications

Specification Status Comment
WHATWG 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.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

ドキュメントのタグと貢献者

 このページの貢献者: mhl, fscholz, kscarfone, teoli
 最終更新者: mhl,