簡體   English   中英

將HTML插入iframe在Firefox / Chrome / Opera中有效,但在IE7 / 8中則無效

[英]Inserting HTML to iframe works in Firefox/Chrome/Opera but not in IE7/8

下面的代碼從外部頁面加載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);
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM