1. 程式人生 > >js調用瀏覽器打印指定div內容

js調用瀏覽器打印指定div內容

ade try solid 按鈕 http use cat body skin

--打印按鈕事件

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內容