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


   --打印按钮事件

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM