相关疑难解决方法(0)

IE10中的跨源postMessage是否被破坏?

我正试图做一个简单的postMessage例子......

  • 在IE10中
  • 在窗口/标签之间(与iframe)
  • 跨越起源

删除这些条件中的任何一个,并且工作正常:-)

但据我所知,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

90
推荐指数
3
解决办法
6万
查看次数

javascript - window.postmessage - event.data始终为null

我有一个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永远是nullevent.orign and event.sourceundefined.我该如何解决这个问题?

javascript iframe firefox postmessage

4
推荐指数
2
解决办法
5135
查看次数