【问题标题】:Open popup from iframe > use that popup to forward the (opener) parent window (IE issue)从 iframe 打开弹出窗口 > 使用该弹出窗口转发(打开器)父窗口(IE 问题)
【发布时间】:2013-08-08 20:27:57
【问题描述】:

此代码在 Chrome/FF/safari 中有效,但在 IE9 中无效。我试图弄清楚 IE 有什么问题。

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

我有这个基于this post/answer的代码

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 (popup 的内容 - JS 应该重定向 popup 的父级)

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

【问题讨论】:

    标签: javascript internet-explorer iframe popup postmessage


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多