JavaScripture
Contribute via GitHub Feedback

BroadcastChannel : EventTarget

BroadcastChannel provides a simple way for different contexts (such as Windows or Workers) in the same origin to broadcast messages all other BroadcastChannels created with the same name. See also Window.postMessage and MessageChannel.

Constructors

new BroadcastChannel(name : String) : BroadcastChannel

Creates a new BroadcastChannel for the specified name.

Example:

Run

Results:

 

Instance Properties

name : String  

Returns the name of the channel.

Example:

Run

Results:

 

Instance Methods

close() : undefined

Causes this to stop listening to message. Allows this to be garbage collected.

Example:

Run

Results:

 

postMessage(message : Object) : undefined

Serializes message and sends it to all other BroadcastChannels sharing the same name as this on the same origin.

Example:

Run

Results:

 

Instance Events

onmessage / 'message'  
listener(event : MessageEvent) : undefined

Fired when postMessage is called on another BroadcastChannel sharing the same name as this.

Example:

Run

Results:

 

onmessageerror / 'messageerror'  
listener(event : MessageEvent) : undefined

Fired when unable to deserialize a message from another BroadcastChannel in this' context.