0

这段代码我在 Chrome/FF/safari 中工作,但在 IE9 中没有。我试图弄清楚 IE 有什么问题。

Domain1.com 有一个托管在 domain2.com 上的 iframe - iframe 触发一个弹出窗口(托管在 domain2.com 上),然后该弹出窗口上的链接 a)将 domain1.com 页面转发到 domain2.com 上的某个位置,b)关闭弹出。

我有这个基于这篇文章/答案的代码

1)domain1.com(上面有 iframe 和 IE 特定代码用于处理事件)

  <script type="text/javascript">
    if(navigator.appName == "Microsoft Internet Explorer")          
        window.attachEvent("onmessage", receiveMessage);
    else
        window.addEventListener("message", receiveMessage, false);            

    function receiveMessage(e) {
      if(e.origin == "http://www.domain2.com") //important for security
        if(e.data.indexOf('redirect:') == 0)
          document.location = e.data.substr(9);
    }
  </script>
<iframe src="http://www.domain2.com/iframetest_deleteme.html" width="400" height="150">      
</iframe>

2)domain2.com(iframe的内容,JS只是一个poup)

<script type="text/javascript" >
 jQuery(function($){ 
        $("a[rel*=external]").click(function(){ 
            window.open("http://domain2.com/iframetest_deleteme_popup.html", "", "location=0, menubar=0, resizable=no, toolbar=no, menubar=no, scrollbars=no, width=300, height=100")
            return false; 
        });
 }); 
 </script>
<a href="#" rel="external">open popup from iframe</a>

3)domain2.com(弹出的内容-JS应该重定向弹出的父级)

<script type="text/javascript">
 jQuery(function($){ 
        $("a[rel*=external]").click(function(){             
            opener.parent.postMessage('redirect:http://www.google.com', 'http://domain1.com');
            window.close(this);         
            return false; 
        });
 }); 
 </script>

 <p><a href="#" rel="external">javascript link</a></p>

我已经玩了很长时间了,无法弄清楚为什么 IE9 不能使用它。

它是实时的,可以在所有非 IE 浏览器中进行测试/查看:http: //alexhays.com/test/

4

1 回答 1

1

postmessage 在 ie8 和 ie9 上无法用于弹出通信

http://www.felocity.com/article/window_postmessage_problems_and_workarounds_for_ie8/

于 2013-08-08T12:27:57.700 回答