将CSS应用于printWindow.print();用Java语言编写 [英] Apply CSS to printWindow.print(); in Javascript
本文介绍了将CSS应用于printWindow.print();用Java语言编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在HTML页面中有一个需要打印的部分.我使用以下JS方法进行打印.
I have a section in an HTML page that I need to print. I use the following JS method to print it.
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文件
The problem is that i use 3 css files
Custom.min.css
bootstrap.min.css
components.min.css
在我的打印输出中,我似乎无法应用这些样式.打印出来的图像是原始的.如何应用CSS?
In my print out, I cant seem to have applied these styles. The print is coming out raw. How can I apply CSS?
推荐答案
printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>')
这包括print.css.
this includes print.css.
对其他具有正确路径的css文件执行相同的操作
do the same for the other css files with proper path to the files
这篇关于将CSS应用于printWindow.print();用Java语言编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文