gpt4 book ai didi

javascript - 将 HTML 插入 iframe 在 Firefox/Chrome/Opera 中有效,但在 IE7/8 中无效

转载 作者:行者123 更新时间:2023-11-28 10:24:04 26 4
gpt4 key购买 nike

下面的代码从外部页面加载 HTML 并将其插入到 iframe 中。但它在 IE 中不起作用(IE 完全卡住):

$.ajax({
url: uri,
success: function(response) {
var iframe = document.createElement('iframe');
div.html(iframe);
var doc = iframe.document;
if (iframe.contentDocument) {
doc = iframe.contentDocument; // For NS6
} else if(iframe.contentWindow) {
doc = iframe.contentWindow.document; // For IE5.5 and IE6
}
doc.open();
doc.writeln(response);
doc.close();
},
error: function(response) {
alert(response);
}
});

有什么想法吗?

最佳答案

如果我是你,我会让 jQuery 处理繁重的工作,因为你已经在使用它了:

$.ajax({
url: uri,
success: function(response) {
var iframe = $('<iframe/>');
div.html(iframe);
iframe.contents().find('body').html(response);
},
error: function(response) {
alert(response);
}
});

关于javascript - 将 HTML 插入 iframe 在 Firefox/Chrome/Opera 中有效,但在 IE7/8 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4875401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com