files/en-us/web/api/location/assign/index.md
{{ APIRef("HTML DOM") }}
The assign() method of the {{DOMXref("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.
assign(url)
url
https://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.SecurityError {{domxref("DOMException")}}
SyntaxError {{domxref("DOMException")}}
url parameter is not a valid URL.None ({{jsxref("undefined")}}).
// 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}}
{{Compat}}