網頁打印樣式設置(頁眉,頁腳,頁邊距)


<SCRIPT language=javascript>
    var HKEY_Root, HKEY_Path, HKEY_Key;
    HKEY_Root = "HKEY_CURRENT_USER";
    HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    var head, foot, top, bottom, left, right;

    //取得頁面打印設置的原參數數據    
    function PageSetup_temp() {
        try {
            var Wsh = new ActiveXObject("WScript.Shell");
            HKEY_Key = "header";
            //取得頁眉默認值    
            head = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
            HKEY_Key = "footer";
            //取得頁腳默認值    
            foot = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
            HKEY_Key = "margin_bottom";
            //取得下頁邊距    
            bottom = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
            HKEY_Key = "margin_left";
            //取得左頁邊距    
            left = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
            HKEY_Key = "margin_right";
            //取得右頁邊距    
            right = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
            HKEY_Key = "margin_top";
            //取得上頁邊距    
            top = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
        } catch(e) {
            alert("不允許ActiveX控件");
        }
    }

    //設置網頁打印的頁眉頁腳和頁邊距    
    function PageSetup_Null() {
        try {
            var Wsh = new ActiveXObject("WScript.Shell");
            HKEY_Key = "header";
            //設置頁眉(為空)    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
            HKEY_Key = "footer";
            //設置頁腳(為空)    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
            HKEY_Key = "margin_bottom";
            //設置下頁邊距(0)    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
            HKEY_Key = "margin_left";
            //設置左頁邊距(0)    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
            HKEY_Key = "margin_right";
            //設置右頁邊距(0)    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
            HKEY_Key = "margin_top";
            //設置上頁邊距(8)    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.313");
        } catch(e) {
            alert("不允許ActiveX控件");
        }
    }
    //設置網頁打印的頁眉頁腳和頁邊距為默認值    
    function PageSetup_Default() {
        try {
            var Wsh = new ActiveXObject("WScript.Shell");
            HKEY_Key = "header";
            HKEY_Key = "header";
            //還原頁眉    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, head);
            HKEY_Key = "footer";
            //還原頁腳    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, foot);
            HKEY_Key = "margin_bottom";
            //還原下頁邊距    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, bottom);
            HKEY_Key = "margin_left";
            //還原左頁邊距    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, left);
            HKEY_Key = "margin_right";
            //還原右頁邊距    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, right);
            HKEY_Key = "margin_top";
            //還原上頁邊距    
            Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, top);
        } catch(e) {
            alert("不允許ActiveX控件");
        }
    }

    function printorder() { //gettime();
        PageSetup_temp(); //取得默認值    
        PageSetup_Null(); //設置頁面    
        factory.execwb(6, 6); //打印頁面    
        PageSetup_Default(); //還原頁面設置    
        //factory.execwb(6,6);    
        window.close();
    }
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM