aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/location/assign
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/location/assign
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/location/assign')
-rw-r--r--files/zh-cn/web/api/location/assign/index.html71
1 files changed, 71 insertions, 0 deletions
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
+---
+<p>{{ APIRef("HTML DOM") }}</p>
+
+<p><code><strong>Location.assign()</strong></code> 方法会触发窗口加载并显示指定的URL的内容。</p>
+
+<p>如果由于安全原因无法执行跳转,那么会抛出一个 <code>SECURITY_ERROR</code> 类型的 {{domxref("DOMException")}}。当调用此方法的脚本来源和页面的 {{domxref("Location")}} 对象中定义的来源隶属于不同域的时候,就会抛出上述错误。</p>
+
+<p>如果传入了一个无效的 URL,则会抛出一个 <code>SYNTAX_ERROR</code> 类型的 {{domxref("DOMException")}}。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><var>location</var>.assign(<var>url</var>);
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>url</code></dt>
+ <dd>一个包含了要跳转到的链接的{{domxref("DOMString")}}。</dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush: js">// 跳转到 Location.reload() 这篇文章
+ document.location.assign('https://developer.mozilla.org/zh-CN/docs/Web/API/Location/reload');</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', "history.html#dom-location-assign", "Location.assign()")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>和 {{SpecName("HTML5 W3C")}} 相同。</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "browsers.html#dom-location-assign", "Location.assign()")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>第一次被定义。</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Location.assign")}}</p>
+
+<h2 id="相关内容">相关内容</h2>
+
+<ul>
+ <li>父级接口 {{domxref("Location")}}。</li>
+ <li>相似的方法:{{domxref("Location.replace()")}} 和 {{domxref("Location.reload()")}}。</li>
+</ul>