jquery - 在 IE8 中打印带有背景颜色的 div 内容

标签 jquery html css canvas internet-explorer-8

我正在尝试使用 jquery 打印一个 div。 (窗口。打印())。 div 有背景色。当我尝试打印时,它只是不会打印背景颜色。有什么办法吗。

在 IE9 及更高版本中,我已经设法使用 html2canvas 将其转换为图像 uri,但这在 IE8 上不起作用。

如果有任何解决方法,请告诉我。谢谢

最佳答案

没有完美的解决方案,但您可以使用 @media print 为您的打印添加样式,然后为您的 div 定义您想要的样式

enter image description here

-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/

相关文章:

html - 创建与 Word 文档相同的 HTML 文档

jquery - 将 jQuery .css() 与变量一起使用

javascript - 每个循环从 jQuery 创建 JSON

php - 在不刷新 jquery 的情况下附加一个 div

jquery - 为什么 Chrome 会忽略本地 jQuery cookie?

Javascript 最佳实践和文档就绪

php - PHP 中高效的字符串替换

javascript - 在 HTML 中动态显示 JavaScript 数组

html - 如何进行以下更改(表格元素样式)

html - 这个 margin 是从哪里来的?