• 系统程序添加打印功能


    HTML 标签

    </div>
    <button class="btn btn-primary" type="button" id="bt" onclick="print()">打印</button>
    </div>

    打印的JS代码

    <script>
    var authJson = eval('@ViewBag.AuthJsonStr');
    function print() {
    var userAgent = navigator.userAgent.toLowerCase(); //取得浏览器的userAgent字符串
    if (userAgent.indexOf("trident") > -1) {
    alert("请使用google或者360浏览器打印");
    return false;
    } else if (userAgent.indexOf('msie') > -1) {
    var onlyChoseAlert = simpleAlert({
    "content": "请使用Google或者360浏览器打印",
    "buttons": {
    "确定": function () {
    onlyChoseAlert.close();
    }
    }
    })
    alert("请使用google或者360浏览器打印");
    return false;
    } else {//其它浏览器使用lodop
    var oldstr = document.body.innerHTML;
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body></html>";
    //执行隐藏打印区域不需要打印的内容
    document.getElementById("CostPager").style.display = "none";
    var printData = document.getElementById("ToPrintTable").innerHTML; //获得 div 里的所有 html 数据
    var wind = window.open("", "newwin",
    "toolbar=no,scrollbars=yes,menubar=no");
    wind.document.body.innerHTML = headstr + printData + footstr;
    wind.print();
    //打印结束后,放开隐藏内容
    document.getElementById("otherpho").style.display = "block";
    wind.close();
    window.document.body.innerHTML = oldstr;
    }
    }
    </script>

  • 相关阅读:
    第一次Java作业
    第十一次作业
    第十次作业
    第九次作业
    第八次作业
    第七次作业
    第六次作业
    Java中数组自定义排序与优先级队列笔记
    力扣每日一题:删除链表的倒数第N个节点
    又一次离谱的错误——运算符优先级
  • 原文地址:https://www.cnblogs.com/ypyp123/p/13533304.html
Copyright © 2020-2023  润新知