BroadcastChannel()

BroadcastChannel() 构建函数用于创建一个 BroadcastChannel 对象,并与对应的频道相关联。

Note: 此特性在 Web Worker 中可用。

语法

 channel = new BroadcastChannel(channel);

channel
频道名称,类型为 DOMString;在相同的 下,一个名称只对应一个频道,所有 浏览器上下文 共用。 

示例

// create a new channel listening to the "internal_notification" channel.

var bc = new BroadcastChannel('internal_notification');
bc.postMessage('New listening connected!');

规范

规范 示例 备注
HTML Living Standard
BroadcastChannel()
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
BroadcastChannel() constructorChrome Full support 54Edge Full support ≤79Firefox Full support 38IE No support NoOpera Full support 41Safari No support NoWebView Android Full support 54Chrome Android Full support 54Firefox Android ? Opera Android Full support 41Safari iOS No support NoSamsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

另见