Web APIs
BroadcastChannel.prototype.postMessage()
Broadcasts a structured-cloneable message to other eligible channel objects with matching name.
Formal Syntax & Structure
javascript syntaxjavascript
channel.postMessage(message)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| message | any | Structured-cloneable value. |
Return Value
undefined
Broadcasts a structured-cloneable message to other eligible channel objects with matching name.
Working Example
Example Snippetjavascript
(async () => {const a=new BroadcastChannel("v15-lab-two"),b=new BroadcastChannel("v15-lab-two");try{const got=new Promise(ok=>b.onmessage=e=>ok(e.data));a.postMessage({theme:"dark"});console.log(JSON.stringify(await got));}finally{a.close();b.close();}})()