1.局部打印完成后还原页面
function doPrint() {
bdhtml = window.document.body.innerHTML;
bdhtml2 = window.document.body.innerHTML;
sprnstr = "<!--startprint-->";//打印起始行
eprnstr = "<!--endprint-->";//打印结束行
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
var mediaQueryList = window.matchMedia('print');
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml2;
window.location.reload();//原代码改动过,忘了有没有这行
}
2.默认横版打印及不显示网址页眉页脚
/*设置页面默认横板及不显示网址页眉,实测谷歌和360浏览器兼容,ie,edge不好使*/
@page {
size: landscape;
margin: 0mm 0mm 0mm 0mm;
}
笔者所做的功能是弹出一个页面打印页面的内容,要求默认横版及不显示网址、页眉页脚。所以最后没有用到局部打印后还原