From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/location/assign/index.html | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 files/zh-cn/web/api/location/assign/index.html (limited to 'files/zh-cn/web/api/location/assign') diff --git a/files/zh-cn/web/api/location/assign/index.html b/files/zh-cn/web/api/location/assign/index.html new file mode 100644 index 0000000000..8bf9c358f8 --- /dev/null +++ b/files/zh-cn/web/api/location/assign/index.html @@ -0,0 +1,71 @@ +--- +title: Location.assign() +slug: Web/API/Location/assign +tags: + - API + - Location + - 参考 + - 导航 + - 方法 + - 跳转 +translation_of: Web/API/Location/assign +--- +

{{ APIRef("HTML DOM") }}

+ +

Location.assign() 方法会触发窗口加载并显示指定的URL的内容。

+ +

如果由于安全原因无法执行跳转,那么会抛出一个 SECURITY_ERROR 类型的 {{domxref("DOMException")}}。当调用此方法的脚本来源和页面的 {{domxref("Location")}} 对象中定义的来源隶属于不同域的时候,就会抛出上述错误。

+ +

如果传入了一个无效的 URL,则会抛出一个 SYNTAX_ERROR 类型的 {{domxref("DOMException")}}。

+ +

语法

+ +
location.assign(url);
+
+ +

参数

+ +
+
url
+
一个包含了要跳转到的链接的{{domxref("DOMString")}}。
+
+ +

示例

+ +
// 跳转到 Location.reload() 这篇文章
+	document.location.assign('https://developer.mozilla.org/zh-CN/docs/Web/API/Location/reload');
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
规范状态备注
{{SpecName('HTML WHATWG', "history.html#dom-location-assign", "Location.assign()")}}{{Spec2('HTML WHATWG')}}和 {{SpecName("HTML5 W3C")}} 相同。
{{SpecName('HTML5 W3C', "browsers.html#dom-location-assign", "Location.assign()")}}{{Spec2('HTML5 W3C')}}第一次被定义。
+ +

浏览器兼容性

+ + + +

{{Compat("api.Location.assign")}}

+ +

相关内容

+ + -- cgit v1.2.3-54-g00ecf