标签:传递 script 添加 解决 style 100% key ext logs
一、发送端(http://a.domain.com):
1、添加一个iframe,指定接收的页面:
<iframe id="receivePage" src="http://b.domain.com/receive.html"></iframe>
2、在js中添加postMessage方法:
document.getElementById("receivePage").contentWindow.postMessage("要传递的数据","*");
二、接收端(http://b.domain.com)的receive.html:
<!doctype html> <html> <head> </head> <body style="height:100%;"> <script type="text/javascript"> window.addEventListener(‘message‘, function(e) { if (e.source != window.parent) return; if(e.origin != "http://a.domain.com")//请求源验证 return; localStorage.YourKey = e.data; }, false); </script> </body> </html>
标签:传递 script 添加 解决 style 100% key ext logs
原文地址:http://www.cnblogs.com/dances/p/7825604.html