部分非专业版的IE11浏览器的情况下使用opener.postMessage()给父页面传递信息的时候无法使用。那是因为这部分浏览器不支持非同源的页面传递信息,非同源就是http://xxx/中的xxx不一样,即使127.0.0.1和真是ip都算非同源。这时候要接收非同源的ip地址就需要这样写。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>父页面</title>
<script>
function openWin(){
var submitWindow = window.open("/", "processingWindow");
submitWindow.location.href = 'about:blank';
submitWindow.location.href = 'http://192.168.81.24:8040/license-api-release/api/page/signCertificate?reqId=8920b18286764429a939082f0c2b1a55';
}
</script>
</head>
<body>
<input type="button" value="点击打开回调页面" onclick="openWin()" />
<!--
<a href="./testzjm.html" target="_blank" >打开我的窗口</a>
-->
<script>
function isIE() {
if (window.ActiveXObject || "ActiveXObject" in window) {
return true;
} else {
return false;
}
}
if (isIE()) {
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('message', function (event) {
alert("IE 收到 " + event.origin + "消息:" + JSON.stringify(event.data));
}, false);
}
/* window.onmessage = function (event) {
alert("IE 收到 " + event.origin + "消息:" + JSON.stringify(event.data));
}*/
} else {
window.addEventListener('message', function (event) {
alert("收到" + event.origin + "消息:" + JSON.stringify(event.data));
}, false);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>子页面</title>
<script>
function tzjm(){
if (typeof window.opener != undefined){
var dataz = {code: 0, data: {message: "回调反馈", type: 1}};
window.opener.postMessage(dataz, "*");
}
}
</script>
</head>
<body>
<input type="button" onclick="tzjm()" value="开启回调事件"/>
</body>
</html>
这里父子页面必须放入web工程中测试,不然父页面open(“/”)打开的就是本地目录了。