在百度文库VIP文档的防盗功能中直接ctrl+p出来的打印页面是空白的,但是网页没有变空白,怎么实现的?
我自己写的效果打印页面是空白,还在打印界面时网页也是空白。
document.body.onbeforeprint=function() {
var div=document.getElementById("dd");
div.style="background-color: white;position: absolute;";
div.style.width=document.body.scrollWidth+"px";
div.style.height=document.body.scrollHeight+"px";
};
document.body.onafterprint=function() {
var div=document.getElementById("dd");
div.style.width="0px";
div.style.height="0px";
};
css控制就行了,什么操作都不用,执行打印操作隐藏body就没有内容了
<style>
@media print{
body{visibility:hidden}
}
</style>
<pre>在百度文库VIP文档的防盗功能中直接ctrl+p出来的打印页面是空白的,但是网页没有变空白,怎么实现的?
我自己写的效果打印页面是空白,还在打印界面时网页也是空白。
document.body.onbeforeprint=function() {
var div=document.getElementById("dd");
div.style="background-color: white;position: absolute;";
div.style.width=document.body.scrollWidth+"px";
div.style.height=document.body.scrollHeight+"px";
};
document.body.onafterprint=function() {
var div=document.getElementById("dd");
div.style.width="0px";
div.style.height="0px";
};</pre>