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 インターフェイスは、特定のオリジン閲覧コンテキストが加入できる名前付きチャンネルを表します。これにより、同じオリジンの異なる文書間(異なるウィンドウ、タブ、フレーム、iframe)の通信を可能にします。 メッセージは、チャンネルに参加しているすべての BroadcastChannel オブジェクトで発生する message イベントを介して配信されます。

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

EventTarget BroadcastChannel

コンストラクター

BroadcastChannel()

名前付きチャンネルにリンクするオブジェクトを作成します。

インスタンスプロパティ

このインターフェイスは、その親である EventTarget からもプロパティを継承します。

BroadcastChannel.name 読取専用

チャンネルの名前を表す文字列を返します。

インスタンスメソッド

このインターフェイスは、その親である EventTarget からもメソッドを継承しています。

BroadcastChannel.postMessage()

同じチャンネルに参加しているそれぞれの BroadcastChannel オブジェクトに、任意の種類のオブジェクトのメッセージを送信します。

BroadcastChannel.close()

チャンネルオブジェクトを閉じます。 これは、新しいメッセージを取得しないことを示し、最終的にガベージコレクションされることを許可します。

イベント

message

メッセージがチャンネルに到着したときに発生します。 onmessage プロパティからも利用できます。

messageerror

逆シリアル化できないメッセージが到着したときに発生します。 onmessageerror プロパティからも利用できます。

仕様書

Specification
HTML
# broadcasting-to-other-browsing-contexts

ブラウザーの互換性

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
BroadcastChannel
BroadcastChannel() constructor
close
message event
messageerror event
name
postMessage

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
User must explicitly enable this feature.
Has more compatibility info.

関連情報