Location.assign()
The Location
.assign()
method causes the window to load and display the document at the URL specified.
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
JavaScript
Copy Code
object.assign(url);
Parameters
- url
- Is a
DOMString
containing the URL of the page to navigate to.
Examples
JavaScript
Copy Code
// Navigate to the Location.reload article document.location.assign('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG 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
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
- The
Location
interface it belongs to. - Similar methods:
Location.replace()
andLocation.reload()
.
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/location/assign