Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 729591 of BroadcastChannel

  • Revision slug: Web/API/BroadcastChannel
  • Revision title: BroadcastChannel
  • Revision id: 729591
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment fix mobile compat mismatch

Revision Content

{{APIRef}}{{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.

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}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatGeckoMobile("38")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

Revision Source

<p>{{APIRef}}{{SeeCompatTable}}</p>

<p>The <code><strong>BroadcastChannel</strong></code> 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 <code>BroadcastChannel</code> objects listening to the channel.</p>

<h2 id="Constructor">Constructor</h2>

<dl>
 <dt>{{domxref("BroadcastChannel.BroadcastChannel", "BroadcastChannel()")}}</dt>
 <dd>Creates an object linking to the named channel.</dd>
</dl>

<h2 id="Properties">Properties</h2>

<p><em>This interface also inherits properties from its parent, {{domxref("EventTarget")}}.</em></p>

<dl>
 <dt>{{domxref("BroadcastChannel.name")}}</dt>
 <dd>Returns a {{domxref("DOMString")}}, the name of the channel.</dd>
 <dt>{{domxref("BroadcastChannel.onmessage")}}</dt>
 <dd>Is an {{domxref("EventHandler")}} property that specifies the function to execute when a {{event("message")}} event is fired on this object.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<p><em>This interface also inherits methods from its parent, {{domxref("EventTarget")}}.</em></p>

<dl>
 <dt>{{domxref("BroadcastChannel.postMessage()")}}</dt>
 <dd>Sends the message, of any type of object, to each <code>BroadcastChannel</code> object listening to the same channel.</dd>
 <dt>{{domxref("BroadcastChannel.close()")}}</dt>
 <dd>Closes the channel object, indicating it won't get any new messages, and allowing it to be, eventually, garbage collected.</dd>
</dl>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "comms.html#broadcastchannel", "BroadcastChannel")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("38")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("38")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>Another, more heavyweight, way of communicating between browser contexts: {{domxref("ServiceWorker")}}.</li>
 <li><a href="/en-US/docs/Web/API/Broadcast_Channel_API">Broadcast Channel API overview</a></li>
</ul>
Revert to this revision