【问题标题】:Printing the contents of a div in IE在 IE 中打印 div 的内容
【发布时间】:2012-10-09 18:38:48
【问题描述】:

好吧,由于某种原因,我的 div 以 Firefox 和 Chrome 中的方式打印出来,但是当我转到 IE 时,它不起作用。它只打印出 div 的一页,然后是页眉和页脚。我尝试添加一些新代码,看看是否可以让它更好地工作,但仍然存在问题。当前代码确实打印得很好,但没有继承它们在页面上而不是在外部样式表中的 div 样式。下面注释掉的代码是他们之前的代码。有人帮忙吗?

    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\">

【问题讨论】:

  • 根据我的经验,在 IE 中打印非常有问题。最好在新窗口中打开内容,然后在该新窗口中调用 print()。
  • 这里有几个链接,您可以查看 stackoverflow.com/questions/10203199/… 第二个链接应该允许您使用 javascript 执行您想做的事情 - boardreader.com/thread/…
  • 这是一个客户端问题,所以请省略服务器端代码。
  • 我得到了解决方案,我必须向它添加不同的 CSS,以便 div 溢出并打印。感谢大家的帮助

标签: c# javascript css internet-explorer


【解决方案1】:

我得到了解决方案,我必须向它添加不同的 CSS,以便 div 溢出并打印。感谢大家的帮助

【讨论】:

    猜你喜欢
    • 2016-12-30
    • 2011-01-16
    • 2021-09-13
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多