Location: assign()
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('https://developer.mozilla.org/en-US/docs/Web/API/Location/reload');
Specifications
Specification |
---|
HTML Standard (HTML) # dom-location-assign-dev |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
assign |
1 |
12 |
1 |
5.5 |
3 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
See also
- The
Location
interface it belongs to. - Similar methods:
Location.replace()
andLocation.reload()
.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Location/assign