iframe 在 IE 8 中无法正确加载

iframe not loading correctly in IE 8

我正在创建一个带有 jquery 的 iframe,方法是给它一个 src,但它在 IE8 中不工作。

$("#DB_window").append("<iframe frameborder='0' hspace='0' style='width:100%;height:100%;' src='"+urlNoQuery[0]+"' id='DB_iframeContent' name='DB_iframeContent"+Math.round(Math.random()*1000)+"' onload='db_showIframe()'> </iframe>");

它发出请求但请求被中止所以我更改了它并尝试使用 ajax

访问它
$("#DB_window").append("<iframe frameborder='0' hspace='0' style='width:100%;height:100%;' data-src='"+urlNoQuery[0]+"' id='DB_iframeContent' name='DB_iframeContent"+Math.round(Math.random()*1000)+"' onload='db_showIframe()'> </iframe>");

并进行 ajax 调用以获取内容

var iframe = $("#DB_window").children('iframe');
        $.ajax({
            url: iframe.data("src"),
//            dataType : "text/html",
            success: function(content) {
                iframe.html(content);
            }
        });

但是在IE8中它只请求"src" url而不请求页面中的css和js引用。所以 iframe 没有正确呈现,它只带有数据,因此没有样式。 IE中如何请求iframe

在第一种情况下,Iframe 请求在 IE 中被中止。所以我开始知道当您尝试在 DOM 元素关闭之前修改它时,IE 会执行此操作。这意味着如果您尝试将一个子元素附加到另一个子元素,而另一个元素(如 document.body)仍在加载,您将收到此错误。如果您使用 .appendChild 等,就会发生这种情况。 所以我使用了 setTimeout 并且它对我有用。

setTimeout(function(){
$("#DB_window").append(...
},2000);