BroadcastChannel.name

BroadcastChannel.name 是类型为 DOMString 的只读属性,是频道的唯一标识。属性 name 是在创建时传入 BroadcastChannel() 构造函数的,所以是只读的。

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

语法

var str = channel.name;

示例

// 连接到指定频道
var bc = new BroadcastChannel('test_channel');

// 其它操作 (如: postMessage, …)

// 在控制台打印频道名称
console.log(bc.name); // "test_channel"

// 当完成后,断开与频道的连接
bc.close();

规范

规范 状态 备注
HTML Living Standard
BroadcastChannel.name
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
nameChrome 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

参见