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