tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

iframe_broadcastchannel.html (947B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <body>
      4  <script type="application/javascript">
      5 
      6 function is(a, b, msg) {
      7  ok(a == b, msg);
      8 }
      9 
     10 function ok(a, msg) {
     11  window.parent.postMessage({ status: a ? "OK" : "KO", message: msg }, "*");
     12 }
     13 
     14 ok("BroadcastChannel" in window, "BroadcastChannel exists");
     15 
     16 var bc = new BroadcastChannel("foobar");
     17 ok(bc, "BroadcastChannel can be created");
     18 is(bc.name, "foobar", "BroadcastChannel.name is foobar");
     19 
     20 ok("postMessage" in bc, "BroadcastChannel has postMessage() method");
     21 
     22 bc.onmessage = function(evt) {
     23  ok(evt instanceof MessageEvent, "evt is a MessageEvent");
     24  is(evt.target, bc, "MessageEvent.target is bc");
     25  is(evt.target.name, "foobar", "MessageEvent.target.name is foobar");
     26  is(evt.target.name, bc.name, "MessageEvent.target.name is bc.name");
     27  is(evt.data, "Hello world from the window!", "Message received from the window");
     28  bc.postMessage("Hello world from the iframe!");
     29 };
     30 
     31  </script>
     32 </body>
     33 </html>