//打印
print:function(){
//获取打印的页面内容
let subOutputRankPrint = document.getElementById('print-div');
let newContent = subOutputRankPrint.innerHTML;
let oldContent = document.body.innerHTML;
document.body.innerHTML = newContent;
//页面打印缩放比例设置
document.getElementsByTagName('body')[0].style.zoom=0.92;
//检测是否是IE 如果是ie进行页眉页脚
if(!!window.ActiveXObject || "ActiveXObject" in window){
var hkey_root, hkey_path, hkey_key;
hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet"+
"Explorer\\PageSetup\\";
try {
var RegWsh = new ActiveXObject("WScript.Shell");
RegWsh.RegWrite(hkey_path + "header", "");
RegWsh.RegWrite(hkey_path + "footer", "");
} catch (e) {}
}
window.print();
window.location.reload();
//将原有页面还原到页面
document.body.innerHTML = oldContent;
return false;
},
}
//chrome下进行页眉页脚消除 使用css 样式进行消除
// 测试ie11,chrome,firefox,edge 可消除页眉页脚
@media print{
@page{
margin:0;
//控制是使用a4还是使用其它纸张规格
size:auto;
}
}
本文来源于网络:查看>/WangYangXiang/article/details/83718171