aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/broadcastchannel/close/index.html
blob: e3eb2018404734add45769702f192e65bdfc27fc (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
---
title: BroadcastChannel.close()
slug: Web/API/BroadcastChannel/close
translation_of: Web/API/BroadcastChannel/close
---
<p>{{APIRef("BroadCastChannel API")}}</p>

<p>通过调用 <strong><code>BroadcastChannel.close()</code></strong> 方法,可以马上断开其与对应频道的关联,并让其被垃圾回收。这是必要的步骤,因为浏览器没有其它方式知道频道不再被需要。</p>

<p>{{AvailableInWorkers}}</p>

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

<pre class="syntaxbox">var <em>str</em> = <em>channe<code>l</code></em><code>.close();</code>
</pre>

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

<pre class="brush: js">// 连接到指定频道
var bc = new BroadcastChannel('test_channel');

// 其它操作 (如: postMessage, …)

// 当完成后,断开与频道的连接
bc.close();
</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', "comms.html#dom-broadcastchannel-close", "BroadcastChannel.close()")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("api.BroadcastChannel.close")}}</p>

<h2 id="另见">另见</h2>

<ul>
 <li>{{domxref("BroadcastChannel")}}, the interface it belongs to.</li>
</ul>