復制代碼 代碼如下:
var hkey_root = "HKEY_CURRENT_USER";
var hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
var hkey_key;
function printPage() {
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 因為我不想顯示當前打印頁的網址
hkey_key = "margin_bottom";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.39"); //0.39相當於把頁面設置裡面的邊距設置為10
hkey_key = "margin_left";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.39");
hkey_key = "margin_right";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.39");
hkey_key = "margin_top";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.39");
}
catch (e) { }
var headstr = "<html><head></head><body>";
var footstr = "</body>";
var newWin = window.open('printer', '', '');
var titleHTML = document.getElementById("printdiv").innerHTML;
newWin.document.write(headstr + titleHTML + footstr);
newWin.document.location.reload();
newWin.print();
// newWin.close();
}