BroadcastChannel()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.

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

BroadcastChannel() 构造函数用于创建一个 BroadcastChannel 对象,并与底层的通道相关联。

语法

js
new BroadcastChannel(channelName)

参数

channelName

表示通道名称的字符串;对于同下的所有浏览上下文,一个名称只对应一个通道。

示例

js
// 创建一个监听“internal_notification”通道的新通道。

const bc = new BroadcastChannel("internal_notification");
bc.postMessage("新的监听连接!");

规范

Specification
HTML
# dom-broadcastchannel-dev

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
BroadcastChannel() constructor

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
User must explicitly enable this feature.

参见