BroadcastChannel()

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() コンストラクターは、新しい BroadcastChannel を作成し、それを基礎となるチャンネルに接続します。

注: この機能は Web Worker 内で利用可能です。

構文

js
new BroadcastChannel(channelName)

channelName

文字列で、チャンネルの名前を表します。 同じオリジンを持つすべての閲覧コンテキストに対して、この名前を持つ単一のチャンネルがあります。

js
// "internal_notification" チャンネルをリッスンする新しいチャンネルを作成します。

const bc = new BroadcastChannel("internal_notification");
bc.postMessage("New listening connected!");

仕様書

Specification
HTML Standard
# dom-broadcastchannel-dev

ブラウザーの互換性

BCD tables only load in the browser

関連情報