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

2019/03/04 11:36
阅读数 17

   --打印按钮事件

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) {
    }
   }

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部