{{APIRef("BroadCastChannel API")}}{{SeeCompatTable}}
The BroadcastChannel
interface represents a named channel that any {{glossary("browsing context")}} of a given {{glossary("origin")}} can subscribe to. It allows communication between different documents (in different windows, tabs, frames or iframes) of the same origin. Messages are broadcasted via a {{event("message")}} event fired at all BroadcastChannel
objects listening to the channel.
{{AvailableInWorkers}}
Constructor
- {{domxref("BroadcastChannel.BroadcastChannel", "BroadcastChannel()")}}
- Creates an object linking to the named channel.
Properties
This interface also inherits properties from its parent, {{domxref("EventTarget")}}.
- {{domxref("BroadcastChannel.name")}}
- Returns a {{domxref("DOMString")}}, the name of the channel.
- {{domxref("BroadcastChannel.onmessage")}}
- Is an {{domxref("EventHandler")}} property that specifies the function to execute when a {{event("message")}} event is fired on this object.
Methods
This interface also inherits methods from its parent, {{domxref("EventTarget")}}.
- {{domxref("BroadcastChannel.postMessage()")}}
- Sends the message, of any type of object, to each
BroadcastChannel
object listening to the same channel. - {{domxref("BroadcastChannel.close()")}}
- Closes the channel object, indicating it won't get any new messages, and allowing it to be, eventually, garbage collected.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "comms.html#broadcastchannel", "BroadcastChannel")}} | {{Spec2('HTML WHATWG')}} | Initial definition. |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatGeckoDesktop("38")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Available in workers | {{CompatNo}} | {{CompatGeckoDesktop("38")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile("38")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Available in workers | {{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile("38")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
See also
- Another, more heavyweight, way of communicating between browser contexts: {{domxref("ServiceWorker")}}.
- Broadcast Channel API overview