我正在尝试使用 jquery 打印一个 div。 (窗口。打印())。 div 有背景色。当我尝试打印时,它只是不会打印背景颜色。有什么办法吗。
在 IE9 及更高版本中,我已经设法使用 html2canvas 将其转换为图像 uri,但这在 IE8 上不起作用。
如果有任何解决方法,请告诉我。谢谢
最佳答案
没有完美的解决方案,但您可以使用 @media print
为您的打印添加样式,然后为您的 div
定义您想要的样式
-webkit-print-color-adjust: exact;
仅适用于像 chrome 这样的 webkit 浏览器。引用:https://developer.mozilla.org/en/docs/Web/CSS/-webkit-print-color-adjust
function myFunction() {
background: window.print();
}
@media print {
div {
background-color: red;
-webkit-print-color-adjust: exact;
}
}
div {
background-color: red;
}
<div>I'm the div and I should be red</div>
<button onclick="myFunction()">Print this page</button>
关于jquery - 在 IE8 中打印带有背景颜色的 div 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44052816/