BroadcastChannel()

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.

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

メモ: この機能はウェブワーカー内で利用可能です。

構文

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

関連情報