控制IE列印時的頁首頁尾
 
<script language="javascript">
// 列印
function fnPrint() {
        try    {
                // 儲存原本頁首頁尾的設定,然後設定空白
                var ret = saveAndClearSetting();
                // 列印
                window.print();
                // 回存原本頁首頁尾的設定
                if ( ret ) restoreSetting();
        } 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 old_header = "&w&b &p 頁,共 &P ";
var old_footer = "&u&b&d";
// 儲存原本頁首頁尾的設定,然後設定空白
function saveAndClearSetting() {
try {
        var RegWsh = new ActiveXObject("Wscript.Shell");
        old_header = RegWsh.RegRead(hkey_key_header);
        old_footer = RegWsh.RegRead(hkey_key_footer);
        RegWsh.RegWrite(hkey_key_header,"");
        RegWsh.RegWrite(hkey_key_footer,"");
        return true;
} catch (e) {
        if ( e.description.indexOf("伺服程式無法產生物件") != -1 ) {
                alert("請調整IE瀏覽器的安全性\n網際網路選項\安全性\自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。");
        } // if
        else {
                alert("ERR="+e.description);
        } // else
} // catch
        return false;
}
// 回存原本頁首頁尾的設定
function restoreSetting() {
try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_key_header,old_header);
        RegWsh.RegWrite(hkey_key_footer,old_footer);
} catch (e) {
        if ( e.description.indexOf("伺服程式無法產生物件") != -1 ) {
                alert("請調整IE瀏覽器的安全性\n網際網路選項\安全性\自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。");
        } // if
        else {
                alert("ERR="+e.description);
        } // else
} // catch
}
</script>
參考網址
http://klcintw4.blogspot.com/2007/09/javascriptie.html
arrow
arrow
    全站熱搜

    lien0130 發表在 痞客邦 留言(0) 人氣()