呼叫 DoPrint() 執行列印
透過 WScript.Shell 修改頁面設置的登錄值
- function DoPrint()
- {
- try
- {
- // 設定頁首頁尾及邊界
- var ret = saveAndClearSetting();
- // 列印
- window.print();
- }
- catch (e)
- {
- alert("err="+e.description);
- }
- }
- var hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
- var hkey_key_header = hkey_path + "header"; // 頁首
- var hkey_key_footer = hkey_path + "footer"; // 頁尾
- var hkey_key_margin_bottom = hkey_path + "margin_bottom"; // 邊界(下)
- var hkey_key_margin_left = hkey_path + "margin_left"; // 邊界(左)
- var hkey_key_margin_right = hkey_path + "margin_right"; // 邊界(右)
- var hkey_key_margin_top = hkey_path + "margin_top"; // 邊界(上)
- var topMargin = 5; //***注意: IE預設的單位為公厘(mm)
- var leftMargin = 5;
- var rightMargin = 5;
- var bottomMargin = 5;
- // 設定頁首頁尾及邊界
- function saveAndClearSetting()
- {
- try
- {
- var RegWsh = new ActiveXObject("WScript.Shell");
- RegWsh.RegWrite(hkey_key_header, ""); //頁首頁尾設為空白
- RegWsh.RegWrite(hkey_key_footer, "");
- RegWsh.RegWrite(hkey_key_margin_bottom, parseFloat(bottomMargin)/10/2.54); //***注意: 登錄值的單位為公吋
- RegWsh.RegWrite(hkey_key_margin_right, parseFloat(rightMargin)/10/2.54);
- RegWsh.RegWrite(hkey_key_margin_left, parseFloat(leftMargin)/10/2.54);
- RegWsh.RegWrite(hkey_key_margin_top, parseFloat(topMargin)/10/2.54);
- return true;
- }
- catch (e)
- {
- if ( e.description.indexOf("伺服程式無法產生物件") != -1 )
- alert("請調整IE瀏覽器的安全性\n網際網路選項\安全性\自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。");
- else
- alert("ERR="+e.description);
- }
- return false;
- }
全站熱搜