<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script> window.onload = function() { document.getElementById("btn").onclick = function() { document.getElementById("f").contentWindow.postMessage(document.getElementById("t").value, "*"); }; }; </script> </head> <body> <input id="t" type="text" /> <input id="btn" type="button" /> <iframe id="f" src="receiveMsg.html" ></iframe> </body> </html>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript"> window.onmessage = function (event) { //event.data 数据 event.origin 消息来源地址 event.source 源DOMWindow 对象 alert(event.data); alert(event.origin); alert(event.source); } </script> </head> <body> </body> </html>
HTML5学习之跨文档传输消息(七),布布扣,bubuko.com
原文:http://www.cnblogs.com/yxlblogs/p/3896751.html