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

<p><code><strong>BroadcastChannel()</strong></code> 构建函数用于创建一个 {{domxref("BroadcastChannel")}} 对象,并与对应的频道相关联。</p>

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

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

<pre class="syntaxbox"> <em>channel</em> = new BroadcastChannel(<em>channel</em>);</pre>

<h3 id="值"></h3>

<dl>
 <dt><em>channel</em></dt>
 <dd>频道名称,类型为 {{domxref("DOMString")}};在相同的 {{glossary("origin", "源")}} 下,一个名称只对应一个频道,所有 {{glossary("browsing context", "浏览器上下文")}} 共用。 </dd>
</dl>

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

<pre class="brush: js">// create a new channel listening to the "internal_notification" channel.

var bc = new BroadcastChannel('internal_notification');
bc.postMessage('New listening connected!');
</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", "BroadcastChannel()")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

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



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

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

<ul>
 <li>所属接口:{{domxref("BroadcastChannel")}}</li>
</ul>