Jquery调用打印机打印(包含去除页眉页脚)

个人小说网站友书-绿色、纯净、无广告欢迎广大同行前来指点、阅读
话不多说,直接上代码,

function Print(data) {
                $.post("../../program/ashx/PrintAshx.ashx", { Id: data, OrderId: $("#HiddenField1").val() }, function (data) {
                    if (data != "" && data != null && data != undefined) {
                        var head = "<html><head><title></title></head><body><OBJECT classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2' height='0' id='WebBrowser3' width='0' VIEWASTEXT></OBJECT><div align='center'><table width=250px align='center'>";//先生成头部
                        var foot = "</table></div></body></html>";//生成尾部
                        var newstr = "";
                        newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px">单据编号:' + data["djbh"] + '</td></tr>';
                        newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px">机构:' + data["jigou"] + '</td></tr>';
                        newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px">中心:' + data["center"] + '</td></tr>';
                        newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px" align="left">-------------------收款清单-------------------</td></tr>'
                        newstr += '<tr><td style="font-size:10px" colspan="4">付款人:' + data["fukuan"] + '     ' + "\t\t\t" + '打印时间:' + data["sysdt"] + '</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4">------------------------------------------------</td></tr>';
                        newstr += '<tr><td style="font-size:10px" style="width:20%" align="center"></br>序号</td><td style="width:40%;font-size:10px" align="center">项目</td><td style="width:20%;font-size:10px" align="center">数量</td><td style="width:20%;font-size:10px" align="center">金额</td></tr>';
                        newstr += '<tr><td style="font-size:10px" style="width:20%;font-size:10px" align="center">' + data["xh"] + '</td><td style="width:50%;font-size:10px" align="center">' + data["item"] + '</td><td style="width:10%;font-size:10px" align="center">' + data["shuliang"] + '</td><td style="width:20%;font-size:10px" align="center">' + data["zongjia"] + '</td></tr>';
                        newstr += "<tr></tr>" + data["youhui"];
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>应付合计:' + data["yingfu"] + '</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>支付金额:' + data["shifu"] + '</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>支付时间:' + data["sysdt"] + '</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>------------------------------------------------</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4">收款人:' + data["username"] + '</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4">------------------------------------------------</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>备注:此单为缴款凭证,请妥善保存</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>联系电话:' + data["tel"] + '</td></tr>';
                        newstr += '<tr><td style="font-size:10px" colspan="4"></br>地址:' + data["dizhi"] + ' </td></tr>';

----------------------------以上内容为拼接要打印的html页面------------------
                        var oldstr = document.body.innerHTML;//获取原本网页页面代码
                        document.body.innerHTML = head + newstr + foot;//拼接打印页面
                        if (getExplorer() == "IE") {//判断是否IE浏览器,是,调用去除页眉页脚的方法,否,直接输出即可
                            pagesetup_null();
                        }
                        window.print();
                        document.body.innerHTML = oldstr;//还原网页;  
                        return false;

                    }
                }, "Json");
            }

            function pagesetup_null() {
                var hkey_root, hkey_path, hkey_key;
                hkey_root = "HKEY_CURRENT_USER";
                hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
                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, "");
                } catch (e) { }
            }

            function getExplorer() {
                var explorer = window.navigator.userAgent;
                //ie 
                if (explorer.indexOf("MSIE") >= 0) {
                    return "IE";
                }
                    //firefox 
                else if (explorer.indexOf("Firefox") >= 0) {
                    return "Firefox";
                }
                    //Chrome
                else if (explorer.indexOf("Chrome") >= 0) {
                    return "Chrome";
                }
                    //Opera
                else if (explorer.indexOf("Opera") >= 0) {
                    return "Opera";
                }
                    //Safari
                else if (explorer.indexOf("Safari") >= 0) {
                    return "Safari";
                }
            }

结果截图展示:
这里写图片描述

这里写图片描述

如有问题,请加我QQ:631931078或352167311

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

纪寻川

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值