Location: assign() - Web APIs 编辑
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/wiki/en-US/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
BCD tables only load in the browser
See also
- The
Location
interface it belongs to. - Similar methods:
Location.replace()
andLocation.reload()
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论