日期:2014-05-16  浏览次数:20374 次

ie下访问同域下的iframe被拒绝
自己做的一个异步文件上传,在chrome下运行正常,但是在ie下就提示[SCRIPT5: 拒绝访问]

$(document).ready(function(e) {
$('#upload').click(function(e){
$('body').append('<iframe name="cIfram" src="http://localhost/cross/cross.php" style="display:none;"></iframe>');
$('body').append('<form style="display:none;" id="form" action="http://localhost/cross/cross.php" method="post" target="cIfram" enctype="multipart/form-data" encoding="multipart/form-data"><input type="file" id="select" name="File"/></form>');
$('#select').change(function(e){
$("iframe[name='cIfram']").load(function(e) {
e.target.contentWindow.document.domain=document.domain='localhost';//这句是查资料说要使用同源策略,但是也没用啊,而且他们本身就是同源
console.log($($(this).contents().get(0)).find('body').html());
});
$('#form').submit();
});
$('#select').click();
return false;
});
});


好无语的问题,大家来帮我看看吧 -_-
------解决方案--------------------
试试这样

$(document).ready(function(e) {
    $('#upload').click(function(e){
var iframe = document.createElement("iframe");
iframe.setAttribute("id", "cIfram");
iframe.setAttribute("name", "cIfram");
iframe.setAttribute("src", "javascript:false;");
iframe.style.display = "none";
document.body.appendChild(iframe);

var form = document.createElement("form");
form.setAttribute("action", "http://localhost:8080/gtyz/test");
form.setAttribute("target", iframe.name);
form.setAttribute("id", "form");
form.setAttribute("name", "form");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("method", "post");
form.style.display = "none";
document.body.appendChild(form);
        
var file = document.createElement("input");
file.setAttribute("id", "select");
file.setAttribute("type", "file");
form.appendChild(file);

        
        $('#select').change(function(e){
            $('#form').submit();
        });
        $('#select').click();
        return false;
    });
});

------解决方案--------------------
src="/cross/cross.php"   //使用相对绝对地址看看,不要使用绝对地址。
------解决方案--------------------
引用:
引用:试试这样
JavaScript code?1234567891011121314151617181920212223242526272829303132$(document).ready(function(e) {    $('#upload').click(function(e){    var iframe = documen……


数据可以提交不就是了么。。
iframe里要获取啥数据??

看上去是没有本质区别。。但是IE下直接append(html)就是有问题
------解决方案--------------------
console.log
ie下面有这个吗?
你是什么版本的。你用相对地址吧。
不要加http://localhost:8080/cross
试试看吧。
------解决方案--------------------
引用:
引用:引用:引用:试试这样
JavaScript code?1234567891011121314151617181920212223242526272829303132$(document).ready(function(e) {    $('#u