我正试图做一个简单的postMessage例子......
删除这些条件中的任何一个,并且工作正常:-)
但据我所知,postMessage当两个窗口共享一个原点时,窗口之间似乎只能在IE10中工作.(嗯,事实上 - 奇怪的是 - 行为稍微宽容一点:共享主机的两个不同的起源似乎也有效).
(注意:这个问题触及了问题,但它的答案是关于IE8和IE9 - 而不是10)
更多细节+例子......
<!DOCTYPE html>
<html>
<script>
window.addEventListener("message", function(e){
console.log("Received message: ", e);
}, false);
</script>
<button onclick="window.open('http://jsbin.com/ameguj/1');">
Open new window
</button>
</html>
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<script>
window.opener.postMessage("Ahoy!", "*");
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
这适用于:http://jsbin.com/ahuzir/1 - 因为两个页面都托管在同一个源(jsbin.com).但是将第二页移到其他地方,它在IE10中失败了.
html5 compatibility postmessage cross-browser internet-explorer-10
我有一个iframe,并希望将数据从iframe发送到父窗口.
在iframe的js代码中,我有以下语句
window.parent.postMessage('hello', '*');
Run Code Online (Sandbox Code Playgroud)
父窗口中的相应消息处理程序如下所示
$(window).bind('message', function (event) {
console.log(event.data);
console.log(event.origin);
console.log(event.source);
console.log('received');
});
Run Code Online (Sandbox Code Playgroud)
我从localhost加载代码,iframe源也从localhost加载.我在firefox 21中运行代码.
问题是,event.data永远是null和event.orign and event.source是undefined.我该如何解决这个问题?