Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年9月.
メモ: この機能はウェブワーカー内で利用可能です。
MessageChannel() は MessageChannel インターフェイスのコンストラクターで、2 つの新しい MessagePort オブジェクトを持つ新しい MessageChannel オブジェクトを返します。
なし (undefined)。
新しい MessageChannel オブジェクト。
次のコードブロックでは、MessageChannel() コンストラクターを使用して作成された新しいチャンネルを知ることができます。 <iframe> が読み込まれると、MessagePort.postMessage にメッセージを添えて MessageChannel.port2 を <iframe> へ渡します。 すると、handleMessage ハンドラーが <iframe> から返送されたメッセージに (MessagePort.message_event を使用して) 返答し、これを段落に挿入します。 port1 は、いつメッセージが到着しているかどうかをチェックするために待ち受けされます。
完全に動作する例は、Github 上の channel messaging basic demo を参照してください (実際のデモも実行できます)。
| HTML # dom-messagechannel-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2024年8月20日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.