Languages
[Edit]
EN

JavaScript - send messages between windows with BroadcastChannel

8 points
Created by:
Elleanor-Williamson
380

In this article, we would like to show you how we can communicate between different browser tabs.

Messages sending beetween windows with BroadcastChannel - JavaScript
Messages sending between windows with BroadcastChannel - JavaScript

Quick solution: 

BroadcastChannel allows communication between tabs, frames, iframes and windows. The connection is made in the browser and doesn't need a backend. 

The message is broadcast using the postMessage() method and the recipients are windows that listen through the addEventListener.

Note:

Open this post in two or more tabs/windows, run example and send messages.

Practical example: 

Note: 

BroadcastChannel interface is not supported in Internet Explorer, Safari and older browsers, so use with caution.

References

Edit
  1. BroadcastChannel - MDN Docs
  2. BroadcastChannel API - MDN Docs

Alternative titles

  1. JavaScript - send messages between tabs with BroadcastChannel
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join