Aspx页面
<INPUT onclick="doPrint('myDiv','btnPrint','btnBack')" id="btnPrint" type="button" value="打印" class="button2">
Printer.js//直接修改注册表
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER" //注册表根目录
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
//设置网页打印的页眉页脚为空
function pagesetup_null(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"//页眉
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
hkey_key="footer"//页脚
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
hkey_key = "margin_left"//左边距
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.7520")
hkey_key = "margin_right"//右边距
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.7520")
hkey_key = "margin_top"//上边距
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.0")
hkey_key = "margin_bottom"//下边距
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.0")
}catch(e){}
}
function doPrint(printDiv,btnPrint,btnBack) {
try {
pagesetup_null();
newwin = window.open("", "newwin", "height=900,width=750,toolbar=no,scrollbars=auto,menubar=no,location=no");
newwin.document.body.innerHTML = document.getElementById(printDiv).innerHTML;
newwin.document.getElementById("table1").style.width = '750';
newwin.document.getElementById("table1").style.height = '900';
newwin.document.getElementById(btnPrint).style.display = 'none';
newwin.document.getElementById(btnBack).style.display = 'none';
newwin.window.print();
newwin.window.close();
// pagesetup_default();
}
catch (e)
{ }
}
//恢复默认值
function pagesetup_default() {
try {
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key = "header";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码,&p/&P")
hkey_key = "footer"
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&u&b&d")
}
catch (e) {
}
}