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

<style type="text/css">
    @media print
        {
            body
            {
                display: inherit/*设置为none,则打印空白,即不能打印*/
            }
        }
</style>
        //获得IE浏览器版本
        function checkIEV() {
            var X, V, N;
            V = navigator.appVersion;
            N = navigator.appName;
            if (N == "Microsoft Internet Explorer")
                X = parseFloat(V.substring(V.indexOf("MSIE") + 5, V.lastIndexOf("Windows")));
            else
                X = parseFloat(V);
            return X;
        }
        //设置为不打印
        function noPrint() {
            var stylef = document.styleSheets[0];
            var rul = stylef.rules[0]; /*上面@media 那一段*/
            rul.style.display = "none";
        }
        

        function checkIEV() {
            var X, V, N;
            V = navigator.appVersion;
            N = navigator.appName;
            if (N == "Microsoft Internet Explorer")
                X = parseFloat(V.substring(V.indexOf("MSIE") + 5, V.lastIndexOf("Windows")));
            else
                X = parseFloat(V);
            return X;
        }
        //设置为不打印
        function noPrint() {
            var stylef = document.styleSheets[0];
            var rul = stylef.rules[0]; /*上面@media 那一段*/
            rul.style.display = "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("WScript.Shell");
                HKEY_Key = "header";
                

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

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

<script type="text/javascript">

                //这里需要浏览器版本,8.0以下的页边距设置与8.0及以上不一样,注意注册表里的单位是英寸,打印设置中是毫米,1英寸=25.4毫米

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值