Web/JSP & JQuery
html 태그 프린트 방법
땀두
2020. 7. 30. 10:20
function printHTML() {
var W = document.documentElement.clientWidth;
if(!W) {
W = document.body.clientWidth;
}
var H = document.documentElement.clientHeight;
if(!H) {
H = document.body.clientHeight;
}
var features = "menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=" + W + ",height=" + H + ",left=0,top=0";
var PrintPage = window.open("about:blank","print",features);
//css 속성들
var printDivCSSLinkRel1 = new String ("<link rel='stylesheet' type='text/css' href='/resources/css/common/common.css' />");
var printDivCSSLinkRel2 = new String ("<link rel='stylesheet' type='text/css' href='/resources/css/common/style.css' />");
PrintPage.document.open();
PrintPage.document.write("<!DOCTYPE html><html><head><title></title>" + printDivCSSLinkRel1 + printDivCSSLinkRel2 + "</head><body>" + document.getElementById('여기에 본인이 프린트할 태그의 아이디 값을 넣으면 됨').innerHTML + "</body></html>");
setTimeout(function(){
PrintPage.document.close();
PrintPage.print();
PrintPage.close();
}, 1000);
}