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

<p>可以使用 <strong><code>BroadcastChannel.postMessage()</code></strong> 发送一条任意 {{jsxref("Object")}} 类型的消息,给所有同{{glossary("origin", "源")}}下监听了该频道的所有{{glossary("browsing context", "浏览器上下文")}}。消息以 {{event("message")}} 事件的形式发送给每一个绑定到该频道的广播频道。</p>

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

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

<pre class="syntaxbox">var <em>str</em> = <em>channe<code>l</code></em><code>.postMessage(<em>object</em>);</code>
</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-postmessage", "BroadcastChannel.postmessage()")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

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



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

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

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