With HTML5, what is the role of MessageChannel and MessagePort Objects for message channel?
While creating messageChannel, it internally creates two ports to sending the data and forwarded to another browsing context.
In this scenario, we are sending the data from one iframe to another iframe. Here we are invoking the data in function and passing the data to DOM.
var loadHandler = function(){ var mc, portMessageHandler; mc = new MessageChannel(); window.parent.postMessage('documentAHasLoaded','https://foo.example',[mc.port2]); portMessageHandler = function(portMsgEvent){ alert( portMsgEvent.data ); } mc.port1.addEventListener('message', portMessageHandler, false); mc.port1.start(); } window.addEventListener('DOMContentLoaded', loadHandler, false);
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more