html5 xdm 页面之间的通信

<!-- 这个是父页面xdm.html -->
<!
DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>XDM通信</title> </head> <body> <iframe id="iframeId" src="http://127.0.0.1:8020/avalon/iframe.html" width="100%" height="600px"></iframe> <script type="text/javascript"> window.addEventListener('load' , function(){ var iframeWindow = document.getElementById('iframeId').contentWindow; iframeWindow.postMessage("滚犊子" , "http://127.0.0.1:8020/avalon/iframe.html"); }); </script> </body> </html>
<!-- 这个是子页面,iframe.html -->
<!
DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body onload="aaaa()"> <script type="text/javascript"> function aaaa(){ window.addEventListener('message' , function(event){ console.log(event); alert(event.data); },false) } </script> </body> </html>
原文地址:https://www.cnblogs.com/xudy/p/6057016.html