web api instance method
Location: assign() method
The assign() method of the Location
interface 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.
Syntax
assign(url)
Parameters
url- : A string or any other object with a stringifier, such as a
URLobject, containing the URL of the page to navigate to; for example, an absolute URL such ashttps://developer.mozilla.org/en-US/docs/Web/API/Location/reload, or a relative URL — such as/Web(just a path, for navigating to another document at the same origin) or#specifications(just a fragment string, for navigating to some part of the same page), and so on.
- : A string or any other object with a stringifier, such as a
Exceptions
SecurityErrorDOMException- : Thrown if the origin of the script calling the method is not the same origin of the page originally described by the
Locationobject, mostly when the script is hosted on a different domain. Browsers also throttle navigations and may throw this error, generate a warning, or ignore the call if it’s called too frequently.
- : Thrown if the origin of the script calling the method is not the same origin of the page originally described by the
SyntaxErrorDOMException- : Thrown if the provided
urlparameter is not a valid URL.
- : Thrown if the provided
Return value
None (undefined).
Examples
// Navigate to the Location.reload article
window.location.assign(
"https://developer.mozilla.org/en-US/docs/Web/API/Location/reload",
);
// Then navigate to its Specifications section
window.location.assign("#specifications");
// Eventually navigate to https://developer.mozilla.org/en-US/docs/Web
window.location.assign("/Web");
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.