【问题标题】:top.window.location internet explorer permission denied errortop.window.location Internet Explorer 权限被拒绝错误
【发布时间】:2011-08-09 14:26:55
【问题描述】:

我想从 iframe 重定向页面,特别是我想从 iframe 重定向首页。

所以我使用:

top.window.location = 'http://xxx'

它在 mozzila 或 chrome 中工作正常,但在 ie 中我得到:权限被拒绝错误。我发现了一些信息,这是跨域脚本问题:

http://www.mombu.com/microsoft/microsoft/t-ie-shows-permission-denied-javascript-error-on-toplocationhre-4565452-last.html

我不知道怎么做 - 将父窗口从 iframe 重定向到某个 url,它位于不同的 url(显然)

感谢您的帮助...

【问题讨论】:

    标签: javascript internet-explorer


    【解决方案1】:

    有一种方法可以跨域重定向父框架。实际上,这是一个技巧。 :-) 如果您可以访问托管父框架的服务器,它将起作用。

    在您的框架内,从与父框架相同的域创建一个子框架,该子框架太小而无法看到。允许您的小子框架更改父文档的位置。

    家长:

    <iframe src="http://other-domain/doc.html"></iframe>
    

    doc.html

    All the stuff from the document...
    <iframe width="0" height="0" src="http://original-domain/trick.html"></iframe>
    

    trick.html
    
    <script>
        window.location.replace("http://xxx");
    </script>
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,使用:

      top.window.location= "http://www.google.com";
      

      我把它改成了:

      window.parent.location = "http://www.google.com";
      

      这为我解决了。

      【讨论】:

      • 欢迎来到 stackoverflow。这篇文章可能会回答这个问题,但更多的解释可能会帮助其他程序员理解它为什么起作用。
      猜你喜欢
      • 2011-02-26
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      相关资源
      最近更新 更多