通过Iframe上传,IE8 / 9访问被拒绝(跨域)

时间:2014-09-26 09:27:20

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

我正在使用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没有被解释......我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试检查两者的协议: iframe中:

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

和父页面:

document.location.protocol

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

其他东西是绝对网址 - 指向另一个网站。