JS 網頁打印 頁邊距 頁眉頁腳

以下示例代碼本人是在IE6下進行的

頁面中的代碼:

<OBJECT id="WebBrowser1" height="0" width="0"
       classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" VIEWASTEXT>
</OBJECT>

相關JS:

var hkey_root, hkey_path, hkey_key
hkey_root = "HKEY_CURRENT_USER"
hkey_path = "//Software//Microsoft//Internet Explorer//PageSetup//"
// 設置 頁眉 頁腳 頁邊距
function PagePrintSetup() {
    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_top";//註冊表中的0.75對應於網頁的19.05
        RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.15");

        //margin_bottom
        //margin_left
        //margin_right
    }
    catch (e) { }
}

function fn_winPrint() {
    document.all.tab_PrintButton.style.display = 'none';

    try {
     PagePrintSetup() ;
        document.all.WebBrowser1.execwb(6, 1);
    }
    catch (err) {
        window.print();
    }

    document.all.tab_PrintButton.style.display = 'block';

    return false;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章