The Location.assign()
method causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.assign()
by pressing the "back" button.
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
location.assign(url);
Parameters
url
- Is a
DOMString
containing the URL of the page to navigate to.
Example
// Navigate to the Location.reload article window.location.assign('/docs/Web/API/Location/reload');
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'Location.assign()' in that specification. |
Living Standard | No change from HTML5. |
HTML5 The definition of 'Location.assign()' in that specification. |
Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
assign | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support 3 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 |
Legend
- Full support
- Full support
See also
- The
Location
interface it belongs to. - Similar methods:
Location.replace()
andLocation.reload()
.