BroadcastChannel.name

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

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

语法

var str = channel.name;

示例

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

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

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

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

规范

Specification
HTML Standard
# dom-broadcastchannel-name-dev

浏览器兼容性

BCD tables only load in the browser

参见