Create BroadcastChannel and post and receive message - Javascript Language Basics

Javascript examples for Language Basics:BroadcastChannel

Description

Create BroadcastChannel and post and receive message

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   ww w.  j  av a 2  s  . co m
var broadcaster = new BroadcastChannel('Consumer');
var messageReceiver= new BroadcastChannel('Consumer');
messageReceiver.onmessage = function(event) {
  console.log(event.data);
}
broadcaster.postMessage("hello");
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials