简体   繁体   English

在IE中打印div的内容

[英]Printing the contents of a div in IE

Ok so for some reason my div prints out the way it should in Firefox and Chrome but then when I go to IE it doesnt work. 好的,出于某种原因,我的div会打印出它在Firefox和Chrome中应该显示的方式,但是当我使用IE时,它不起作用。 It only prints out one page of the div then the header and footer. 它只打印出div的一页,然后打印出页眉和页脚。 I have tried adding some new code to see if I can get it to work better but still having issues. 我尝试添加一些新代码,以查看是否可以使其更好地工作,但仍然有问题。 The current code does print out fine but doesnt inherit the divs styling that they had on the page and not in an external style sheet. 当前代码确实可以很好地打印出来,但不会继承其在页面上而不是在外部样式表中使用的div样式。 The commented out code below is what they had there before. 下面注释掉的代码是他们之前拥有的代码。 Does anyone have any help? 有人有帮助吗?

    function buildPrint() {

        var sourceDiv = document.getElementById("display_div");
        var WindowObject = window.open('', 'print_div', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
        WindowObject.document.writeln(sourceDiv.innerHTML);
        WindowObject.document.close();
        WindowObject.focus();
        WindowObject.print();
        WindowObject.close();

        //document.getElementById("print_div").innerHTML = sourceDiv.innerHTML;
        //window.print();

    }
<asp:Content ID="Content3" ContentPlaceHolderID="BodyPlaceHolder" runat="server">
<div id="display_div">
<asp:CheckBox ID="showAllOptionals" runat="server" Text="Show All Optionals" AutoPostBack="true" />
<asp:Literal ID="mainTable" runat="server" />
</div>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PrintContent" runat="server">
<div id="print_div" style="page-break-after:avoid;">
</div>

</input><input onclick=\"buildPrint();\" id=\"printBtn\" type=\"button\" value=\"Print\">

I got the solution, I had to add different CSS to it so the div overflowed and printed. 我得到了解决方案,我必须向其中添加不同的CSS,以便div溢出并打印出来。 Thanks for all the help 谢谢你的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM