BroadcastChannel:name 属性

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 接口的 name 只读属性返回一个字符串,该字符串使用其名称唯一标识给定频道。此名称在创建时传递给 BroadcastChannel() 构造函数,因此是只读的。

一个字符串。

示例

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

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

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

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

规范

Specification
HTML
# dom-broadcastchannel-name-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
name

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.

参见