js页面设置与打印(页眉页脚,页边距设置)

时间:2025-03-18 07:40:25
<style type="text/css">
    @media print
        {
            body
            {
                display: inherit/*设置为none,则打印空白,即不能打印*/
            }
        }
</style>
        //获得IE浏览器版本
        function checkIEV() {
            var X, V, N;
            V = ;
            N = ;
            if (N == "Microsoft Internet Explorer")
                X = parseFloat((("MSIE") + 5, ("Windows")));
            else
                X = parseFloat(V);
            return X;
        }
        //设置为不打印
        function noPrint() {
            var stylef = [0];
            var rul = [0]; /*上面@media 那一段*/
            = "none";
        }
        

        function checkIEV() {
            var X, V, N;
            V = ;
            N = ;
            if (N == "Microsoft Internet Explorer")
                X = parseFloat((("MSIE") + 5, ("Windows")));
            else
                X = parseFloat(V);
            return X;
        }
        //设置为不打印
        function noPrint() {
            var stylef = [0];
            var rul = [0]; /*上面@media 那一段*/
            = "none";
        }
        //设置网页打印的页眉页脚和页边距
        function PageSetup_Null() {
            var HKEY_Root, HKEY_Path, HKEY_Key;
            HKEY_Root = "HKEY_CURRENT_USER";
            HKEY_Path = "

        function PageSetup_Null() {
            var HKEY_Root, HKEY_Path, HKEY_Key;
            HKEY_Root = "HKEY_CURRENT_USER";
            HKEY_Path = "\\Software\\Microsoft\\InternetExplorer\\PageSetup\\";
            try {
                var Wsh = new ActiveXObject("");
                HKEY_Key = "header";
                

            try {
                var Wsh = new ActiveXObject("");
                HKEY_Key = "header";
                //设置页眉(为空)
                
//(HKEY_Root+HKEY_Path+HKEY_Key)可获得原页面设置   
                (HKEY_Root + HKEY_Path + HKEY_Key, "");
                HKEY_Key = "footer";
                //设置页脚(为空)   
                (HKEY_Root + HKEY_Path + HKEY_Key, "");

                //(HKEY_Root+HKEY_Path+HKEY_Key)可获得原页面设置   
                (HKEY_Root + HKEY_Path + HKEY_Key, "");
                HKEY_Key = "footer";
                //设置页脚(为空)   
                (HKEY_Root + HKEY_Path + HKEY_Key, "");
                if (checkIEV() < 8.0) {
                    HKEY_Key = "margin_left";
                    //设置左页边距
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0.25");
                    HKEY_Key = "margin_right";
                    //设置右页边距
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0.25");
                    HKEY_Key = "margin_top";
                    //设置上页边距
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0.10");
                    HKEY_Key = "margin_bottom";
                    //设置下页边距   
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0.10");
                }
                else {
                    HKEY_Key = "margin_left";
                    //设置左页边距
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0");
                    HKEY_Key = "margin_right";
                    //设置右页边距
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0");
                    HKEY_Key = "margin_top";
                    //设置上页边距
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0.405");
                    HKEY_Key = "margin_bottom";
                    //设置下页边距   
                    (HKEY_Root + HKEY_Path + HKEY_Key, "0.405");
                }
            }
            catch (e) {
                noPrint();
                alert("ActiveX控件被禁用,请按下面步骤操作:\n1、请打开浏览器‘工具’菜单/‘选项’/‘安全’下的‘自定义级别’,\n把‘对没有标记为安全的activex控件进行初始化和脚本运行’设置为‘启用’。\n2、刷新本页 ");
            }
        }
    </script>