aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/closed/index.html
blob: 084eeaa92ed8138bb6842c4ee669bab63ab515c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: Window.closed
slug: Web/API/Window/closed
translation_of: Web/API/Window/closed
---
<div>{{APIRef}}</div>

<h2 id="概述">概述</h2>

<p>此只读属性表示所引用的窗口是否关闭。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><var>isClosed</var> = <var>windowRef</var>.closed;
</pre>

<dl>
 <dt><code>isClosed</code></dt>
 <dd>一个布尔值。 可能的值:
 <ul>
  <li><code>true</code>: 窗口已被关闭。</li>
  <li><code>false</code>: 窗口是打开的。</li>
 </ul>
 </dd>
</dl>

<h2 id="示例">示例</h2>

<h3 id="更改一个弹出窗口的URL">更改一个弹出窗口的URL</h3>

<p>下面的示例演示怎样更改一个已打开的弹出窗口的URL。尝试更改URL之前,它使用window.opener属性来检查有窗口被打开,并且该窗口没有关闭:</p>

<pre class="brush:js">// Check that an opener exists and is not closed
if (window.opener &amp;&amp; !window.opener.closed) {
  window.opener.location.href = "http://www.mozilla.org";
}</pre>

<p>请注意,弹出窗口只能访问打开他们的窗口。</p>

<h3 id="刷新先前打开的弹出窗口">刷新先前打开的弹出窗口</h3>

<p>在这个例子中,函数refreshPopupWindow()调用重载方法的弹出的位置要刷新其数据的对象。如果弹出窗口尚未打开,或者用户已关闭它打开一个新窗口。</p>

<pre class="brush:js">var popupWindow = null;

function refreshPopupWindow() {
  if (popupWindow &amp;&amp; !popupWindow.closed) {
    // popupWindow is open, refresh it
    popupWindow.location.reload(true);
  } else {
    // Open a new popup window
    popupWindow = window.open("popup.html","dataWindow");
  }
}
</pre>

<h2 id="技术说明">技术说明</h2>

<p>HTML5</p>