首页 > Web开发 > 详细

js调用浏览器打印指定div内容

时间:2019-03-04 11:57:39      阅读:435      评论:0      收藏:0      [点我收藏+]

   --打印按钮事件

function printForm(){
    var headstr = ‘<html xmlns:th="http://www.thymeleaf.org">‘+
    ‘<head>‘+
     ‘<style type="text/css">‘+
     ‘table-bordered>thead>tr>th, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>tbody>tr>td, .table-bordered>tfoot>tr>td {‘+
        ‘border: 1px solid #402828;}‘+
     ‘ .select2{min-width: 120px;}‘+
     ‘</style>‘+
    ‘</head>‘+
    ‘<body class="hold-transition skin-blue sidebar-mini ">‘;
    var footstr = "</body>";
    var newstr = document.all.item("div_print").innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr+newstr+footstr;
    if (!!window.ActiveXObject || "ActiveXObject" in window) { //是否ie
     remove_ie_header_and_footer();
    }

  // 打印
    window.print();
   }
   // ie去页眉页脚
   function remove_ie_header_and_footer() {
    var hkey_path;
    hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    try {
     var RegWsh = new ActiveXObject("WScript.Shell");
     RegWsh.RegWrite(hkey_path + "header", "");
     RegWsh.RegWrite(hkey_path + "footer", "");
    } catch (e) {
    }
   }

js调用浏览器打印指定div内容

原文:https://www.cnblogs.com/myobject/p/10469745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!