>在IE10中
>在窗口/标签(与iframe之间)
>跨越起源
删除这些条件中的任何一个,事情工作正常:-)
但是据我所知,窗口之间postMessage只在IE10中工作,当两个窗口共享一个原点。 (事实上,奇怪的是,行为稍微宽松一点:共享一个主机的两个不同的起源似乎也工作)。
这是一个记录的错误吗?任何解决方法或其他建议?
(注意:This question碰到的问题,但its answer是关于IE8和IE9 – 不是10)
更多详细信息示例…
启动器页面demo
<!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>
推出页面demo
<!DOCTYPE html>
<html>
<script>
window.opener.postMessage("Ahoy!","*");
</script>
</html>
这个工作在:http://jsbin.com/ahuzir/1 – 因为两个页面都在同一个源(jsbin.com)。但将第二页移动到其他地方,它在IE10失败。
解决方法
值得注意的是,在你回答的链接,链接到postMessage不是跨IE8和IE9独立的窗口的原点 – 然而,它也写在2009年,IE10之前。所以我不会把它作为一个指示,它是固定的IE10。
至于postMessage本身,http://caniuse.com/#feat=x-doc-messaging明显表示它仍然在IE10中打破,这似乎与您的演示匹配。 caniuse页面链接到this article,其中包含非常相关的报价:
Internet Explorer 8+ partially supports cross-document messaging: it
currently works with iframes,but not new windows. Internet Explorer
10,however,will support MessageChannel. Firefox currently supports
cross-document messaging,but not MessageChannel.
所以你最好的打赌是可能有一个MessageChannel基于codepath,并回退到postMessage如果不存在。它不会让你IE8 / IE9支持,但至少它将与IE10工作。
MessageChannel上的文档:http://msdn.microsoft.com/en-us/library/windows/apps/hh441303.aspx