在IE11中打印iframe无法正常工作

时间:2014-05-13 20:27:39

标签: javascript internet-explorer-11

我目前有一个打印按钮,按下后会创建一个iframe,用html信息填充它,并将其打印给用户。除了IE11之外,所有浏览器都能完美地工作(并且仍在工作)。出于某种原因,在IE11中,它打印整个文档或父元素。

以下是所有必要的代码。

var iframeEle = $("<iframe>").attr("id", "printIframe" + container_ele).css({ width: "0px", height: "0px" }).appendTo("body");
var doc = iframeEle[0].contentWindow.document;

//Open the document interface, write all stylesheets/html content to it, and close it
doc.open();
    //Get stylesheets
    $("link[type='text/css']", "head").each( function() {
        doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
    });
doc.close();

if(b_MSIE) { doc.execCommand('print', false, null); } 
else { iframeEle[0].contentWindow.print(); }

我在关闭文档和打印文档之间添加了更多内容,但在这种情况下无关紧要。

0 个答案:

没有答案
相关问题