We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

这篇翻译不完整。请帮忙从英语翻译这篇文章

The Location.assign() method causes the window to load and display the document at the URL specified.

The Location.assign() 方法发起 window 读取并显示特定URL指向的document 。

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.

假如因为安全违规导致操作失败, 将会抛出一个SECURITY_ERROR type类型的DOMException错误。假如发起请求的脚本源与Location object 对象所描述的原始页面来源不一致时或者大多是情况由于不同的主机分布,会导致发生这类错误。

If the provided URL is not valid, a DOMException of the SYNTAX_ERROR type is thrown.

假如请求的URL是无效的,SYNTAX_ERROR type中的DOMException错误会被抛出。

Syntax

object.assign(url);

Parameters 参数

url
Is a DOMString containing the URL of the page to navigate to.
包含了寻址的URL内容,使用DOMString规范。

Examples

// Navigate to the Location.reload article
例子,载入Location.reload 这篇文章
document.location.assign('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');

Specifications 说明

Specification Status Comment
HTML Living Standard
Location.assign()
Living Standard No change from HTML5.
HTML5
Location.assign()
Recommendation Initial definition.

Browser compatibility 浏览器的兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

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 更多

 

文档标签和贡献者

此页面的贡献者: luyouxin84
最后编辑者: luyouxin84,