Add message event handler for window - Javascript DOM

Javascript examples for DOM:Event

Description

Add message event handler for window

Demo Code

ResultView the demo in separate window

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
   <head> 
      <meta charset="utf-8"> 
   </head> 
   <body> 
      <iframe src="http://your server html"></iframe> 
      <script>
        var token = "abc";
        window.addEventListener("message", receiveMessage, false);
        function receiveMessage(event) {
            if (event.data === "accquireToken")
                event.source.postMessage(token,"*");
        }/*from   w w  w. j a v  a  2 s.c  om*/
    
      </script>  
   </body>
</html>

Related Tutorials