【问题标题】:Apply CSS to printWindow.print(); in Javascript将 CSS 应用于 printWindow.print();在 Javascript 中
【发布时间】:2016-05-19 17:29:38
【问题描述】:

我需要打印 HTML 页面中的一个部分。我使用下面的 JS 方法来打印它。

printWindow.print();

我就是这样做的。

$("#toprint").on("click", function () {

            var divContents = $("#tobebilled").html();
            var printWindow = window.open('', '', 'height=400,width=800');

printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>'); 
            printWindow.document.write('<html><head><title>Print Bill</title>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(divContents);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            printWindow.print();

问题是我使用了 3 个 css 文件

Custom.min.css
bootstrap.min.css
components.min.css

在我的打印输出中,我似乎无法应用这些样式。打印出来的是原始的。如何应用 CSS?

【问题讨论】:

    标签: javascript html twitter-bootstrap css


    【解决方案1】:
    printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>')
    

    这包括 print.css。

    对其他具有正确文件路径的 css 文件执行相同操作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 1970-01-01
      • 2017-10-04
      • 2023-01-31
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      相关资源
      最近更新 更多