Web APIs

BroadcastChannel.prototype.postMessage()

Try the free JavaScript compiler

Broadcasts a structured-cloneable message to other eligible channel objects with matching name.

Formal Syntax & Structure

javascript syntaxjavascript
channel.postMessage(message)

Parameters & Attributes

NameTypeDescription
messageanyStructured-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();}})()
JavaScript Reference