diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/window/name/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/window/name/index.html')
-rw-r--r-- | files/zh-cn/web/api/window/name/index.html | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/window/name/index.html b/files/zh-cn/web/api/window/name/index.html new file mode 100644 index 0000000000..820c916235 --- /dev/null +++ b/files/zh-cn/web/api/window/name/index.html @@ -0,0 +1,66 @@ +--- +title: Window.name +slug: Web/API/Window/name +tags: + - API + - NeedsUpdate + - 参考 + - 属性 +translation_of: Web/API/Window/name +--- +<div>{{APIRef}}</div> + +<p><span class="seoSummary">获取/设置窗口的名称。</span></p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><var>string</var> = window.name; +window.name = <var>string</var>;</pre> + +<h2 id="示例">示例</h2> + +<pre class="brush:js">window.name = "lab_view";</pre> + +<h2 id="备注">备注</h2> + +<p>窗口的名字主要用于为超链接和表单设置目标(targets)。窗口不需要有名称。</p> + +<p>在某些框架里(如,<a href="http://www.thomasfrank.se/sessionvars.html">SessionVars</a> 和 Dojo's <a href="http://www.sitepen.com/blog/2008/07/22/windowname-transport/">dojox.io.windowName</a> ,该属性也被用于作为 JSONP 的一个更安全的备选,来提供跨域通信(cross-domain messaging)。现代 web 应用应使用 <a href="/en-US/docs/Web/API/Window/postMessage">postMessage API</a> 进行敏感的跨域通信。</p> + +<p><code>window.name</code> 会调用 <code>toString</code> 将赋给它的值转换成对应的字符串表示。</p> + +<p>(译注:此处似有不妥,私以为调用的应是 <code>ToString</code> 抽象方法。事实上,如果将一个Symbol类型的值赋给 <code>window.name</code>,会报 <code>TypeError</code>,而非调用 <code>Symbol.toString()</code> 转换成字符串后进行赋值。例如:</p> + +<pre class="brush: js">window.name = Symbol.for('foo'); // TypeError +window.name = Symbol.for('foo').toString(); // "Symbol(foo)" +</pre> + +<p>具体可参见EMCA语言规范中Type Conversion一节。)</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <td>规范</td> + <td>状态</td> + <td>说明</td> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', 'browsers.html#dom-name', 'Window.name')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'browsers.html#dom-name', 'Window.name')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Window.name")}}</p> |