【问题标题】:Upload via Iframe, IE8/9 access is denied (cross domain)通过 iframe 上传,IE8/9 访问被拒绝(跨域)
【发布时间】:2014-09-26 09:27:20
【问题描述】:

我正在使用 iframe 从模式弹出窗口上传文件。文件被发送到服务器并响应良好,但是当我尝试访问 iframe 响应的 contentDocument 时,我得到的访问被拒绝。所以我尝试设置 src :

iframe[0].src = javascript:'<script>window.onload=function({document.write(\\'<script>document.domain=\\\"" + document.domain + "\\\";<\\\\/script>\\');document.close();};<\/script>'

但这并没有改变任何东西......

感谢您的帮助。

更新:

他们都有http...我尝试另一个scr。但是当我使用 console.log 查看响应 iframe 时,我看到了:

<iframe name="iframeTransport1411732701469" src="javascript:(function(){document.open();document.domain="localhost";var ed = window.parent.CodeMirror_boilerplate;document.write(ed);document.close();})()">

所以 javascript 没有被解释......我做错了什么?

【问题讨论】:

    标签: javascript iframe file-upload internet-explorer-8 internet-explorer-9


    【解决方案1】:

    尝试检查两者的协议: 内嵌框架:

    document.getElementById('iframeId').contentWindow.document.location.protocol
    

    和父页面:

    document.location.protocol
    

    如果它们不同(http 与 https),则视为交叉引用域,您无法更改它们。

    另一个是绝对 URL - 指向另一个网站。

    【讨论】:

      猜你喜欢
      • 2010-12-26
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多