打印配置

<script language="javascript" type="text/javascript">
 
    //打印前的方法
    function window.onbeforeprint() {
        if (document.getElementById("btPrint") != null)
            document.getElementById("btPrint").style.display = "none";
    }
    var setActive = false;
    function Print2() {
        pagesetup_null();
        if (setActive == false) {
            if (confirm("请启用IE的ActiveX控件!否则可能引起打印不美观。是否要继续打印?")) {
                window.print();
                document.getElementById("btPrint").style.display = "block";
            }
            else {
                document.getElementById("btPrint").style.display = "block";
            }
        }
        else {
            window.print();
            document.getElementById("btPrint").style.display = "block";
        }
        //window.location.reload();
    }
 
    var hkey_root, hkey_path, hkey_key
    hkey_root = "HKEY_CURRENT_USER"
    hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
    //设置网页打印的页眉页脚为空,打印背景色
    function pagesetup_null() {
        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, "&w&b页码,&p/&p")
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
            hkey_key = "Print_Background"
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "yes")

            hkey_key = "margin_top"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.18");

            hkey_key = "margin_bottom"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.18");

            hkey_key = "margin_left"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.3");

            hkey_key = "margin_right"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.2");
            setActive = true;

        } catch (e) { }
    }
    window.onload = function () {
        var theDiv = document.getElementsByTagName("div")[0];
        theDiv.parentNode.removeChild(theDiv);       
    }
</script>

转载于:https://www.cnblogs.com/lingxzg/archive/2013/01/24/2874793.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值