【发布时间】:2021-11-11 19:32:13
【问题描述】:
我需要打印两个 div 标签之间的内容。打印完成得很好,但不知何故,如果用户选中打印弹出窗口中的“背景图形”复选框,则背景变为蓝色,这是网页的实际背景颜色。是否可以强制用户仅以黑白打印或从品脱弹出窗口中禁用“背景图形”复选框?下面是我所说的“背景图形”复选框的图像:
下面是我的打印代码:
<script>
function printContent(el) {
var restorepage = $('body').html();
document.getElementById('<%=lblDateTime.ClientID %>').style.display = "block";
document.getElementById('<%=lblDateTime.ClientID %>').innerHTML = new Date().toLocaleString();
document.getElementById('<%=acrLogo.ClientID %>').style.display = "block";
document.getElementById('<%=compName.ClientID %>').style.display = "block";
var printcontent = $('#' + el).clone();
printcontent.removeAttr('style');
$('body').empty().html(printcontent);
window.print();
$('body').html(restorepage);
}
</script>
我也试过把它放在页面中:
<style>
article {
-webkit-print-color-adjust: exact;
background: #222;
color: #eee;
}
</style>
下面是我的 div 标签:
<div>
The contents needs to be printed. This is just a test.
</div>
【问题讨论】:
-
您是否尝试过完全隐藏蓝色背景的特定打印机样式表?例如。
<link rel="stylesheet" media="print" href="print.css" />
标签: javascript html jquery css flexbox