在IE10中跨原点postMessage是否断开? [英] Is cross-origin postMessage broken in IE10?

查看:156
本文介绍了在IE10中跨原点postMessage是否断开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个微不足道的 postMessage 示例工作...

I'm trying to make a trivial postMessage example work...


  • 在IE10

  • 在窗口/标签(与iframe之间)


删除这些条件中的任何一个,并且事情很好: - )

Remove any one of these conditions, and things work fine :-)

但是据我所知, postMessage 仅在两个窗口共享一个原点时在IE10中工作。 (事实上​​,奇怪的是,这种行为稍微宽松一些:共享一个主机的两个不同的起源似乎也起作用了。)

But as far as I can tell, between-window postMessage only appears to work in IE10 when both windows share an origin. (Well, in fact -- and weirdly -- the behavior is slightly more permissive than that: two different origins that share a host seem to work, too).

(注意:此问题涉及问题,但它的回答是关于IE8和IE9 - 不是10)

(Note: This question touches on the issues, but its answer is about IE8 and IE9 -- not 10)

更多详情+ example ...

More details + example...

<!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>



启动页面演​​示



launched page demo

<!DOCTYPE html>
<html>
  <script>
    window.opener.postMessage("Ahoy!", "*");
  </script>
</html>

这适用于: http://jsbin.com/ahuzir/1 - 因为这两个网页托管在同一个来源(jsbin.com)。

This works at: http://jsbin.com/ahuzir/1 -- because both pages are hosted at the same origin (jsbin.com). But move the second page anywhere else, and it fails in IE10.

推荐答案

当我最初发布的时候答案:它实际上不工作在IE10。显然,人们发现这有用的其他原因,所以我把它留给后代。原始答案如下:

I was mistaken when I originally posted this answer: it doesn't actually work in IE10. Apparently people have found this useful for other reasons so I'm leaving it up for posterity. Original answer below:

值得注意的是:您链接的答案中的链接指出 postMessage 在IE8和IE9中不是单独的窗口的交叉原点 - 然而,它也是在2009年,IE10到来之前写的。

Worth noting: the link in that answer you linked to states that postMessage isn't cross origin for separate windows in IE8 and IE9 -- however, it was also written in 2009, before IE10 came around. So I wouldn't take that as an indication that it's fixed in IE10.

对于 postMessage 本身而言, a href =http://caniuse.com/#feat=x-doc-messaging> http://caniuse.com/#feat=x-doc-messaging 明显表示它在IE10中仍然损坏,这似乎与您的演示匹配。 caniuse页面链接到本文,其中包含非常相关的报价:

As for postMessage itself, http://caniuse.com/#feat=x-doc-messaging notably indicates that it's still broken in IE10, which seems to match up with your demo. The caniuse page links to this article, which contains a very relevant quote:


Internet Explorer 8+部分支持跨文档消息传递:it
目前与iframe一起使用,但不支持新窗口。但是,Internet Explorer
10将支持MessageChannel。 Firefox目前支持
跨文档消息,但不支持MessageChannel。

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.

c $ c> MessageChannel 的代码路径,并且如果不存在则回退到 postMessage

So your best bet is probably to have a MessageChannel based codepath, and fallback to postMessage if that doesn't exist. It won't get you IE8/IE9 support, but at least it'll work with IE10.

文档 MessageChannel http://msdn.microsoft.com/en-us/library/windows /apps/hh441303.aspx

这篇关于在IE10中跨原点postMessage是否断开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆