BroadcastChannel.postMessage()

Baseline 2022

Newly available

Since March 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

可以使用 BroadcastChannel.postMessage() 发送一条任意 Object 类型的消息,给所有同下监听了该频道的所有浏览器上下文。消息以 message 事件的形式发送给每一个绑定到该频道的广播频道。

备注: 此特性在 Web Worker 中可用。

语法

var str = channel.postMessage(object);

规范

Specification
HTML Standard
# dom-broadcastchannel-postmessage-dev

浏览器兼容性

BCD tables only load in the browser

参见