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

瀏覽器相容性

另見