HTML5 MessageChannel
✓ Published0🌍 Public
AAnsonT
Last edited Sep 11, 2014
Created on Sep 11, 2014
This example demonstrates a two-way messaging system between a parent page and an iframe using the HTML5 MessageChannel API. The parent page sends a test message via `window.postMessage`, while the iframe establishes a dedicated communication port by transferring `channel.port2` through the same method. Both sides attach `onmessage` handlers to their respective ports, enabling direct, bidirectional message exchange triggered by button clicks. The code uses native `MessageChannel`, `postMessage`, and `port1`/`port2` references, with console logging to show the message flow. No external libraries or data sources are involved; the rendering is plain HTML and JavaScript.
AI-generated description