我试图打印使用下面的代码的HTML内容的jQuery的Javascript打印不使用CSS改变
function printTable() {
var divToPrint = document.getElementById("tblTranscript");
newWin = window.open("");
newWin.document.write('<html><head><title>Page</title>');
newWin.document.write('<link rel="stylesheet" href="bootstrap.css"/>');
newWin.document.write('</head><body>');
newWin.document.write(divToPrint.outerHTML);
newWin.document.write('</body></html>');
newWin.print();
newWin.close();
}
$('#print').on('click', function() {
printTable();
})
它显示在打印预览上表中,但CSS的更改不会应用于表。我尝试了不同的组合为CSS href路径。我能够通过浏览器直接访问css文件,但不知何故,它在打印时不显示。
如果使用CSS印刷媒体,没有任何理由需要使用弹出窗口。 – epascarello
您需要可打印的CSS ... bootstrap不可打印 https://www.smashingmagazine.com/2011/11/how-to-set-up-a-print-style-sheet/ – Felix