BroadcastChannel:name 属性

Baseline 已广泛支持

此特性已经十分成熟,可在许多设备和浏览器版本上使用。自 2022 年 3 月起,它已在各浏览器中可用。

注意:此功能在 Web Workers 中可用。

nameBroadcastChannel 接口的一个只读属性,它返回一个字符串,该字符串通过其名称唯一标识给定的频道。此名称在创建时传递给 BroadcastChannel() 构造函数,因此是只读的。

字符串。

示例

js
// Connect to a channel
const bc = new BroadcastChannel("test_channel");

// More operations (like postMessage, …)

// Log the channel name to the console
console.log(bc.name); // "test_channel"

// When done, disconnect from the channel
bc.close();

规范

规范
HTML
# dom-broadcastchannel-name-dev

浏览器兼容性

另见