我試圖打印使用下面的代碼的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