반응형
$(document).ready(function(){
$("#print_btn").on("click", function(){
const completeParam = makeHtml(app_idx); //app_idx : DB에서 불러온 인덱스(상황에 따라 변경)
reportPrint(completeParam);
});
});
//인쇄할 내용을 객체화시킴
function makeHtml(app_idx){
const obj = {html : ''};
let html = '<div class="pagewrap"><div class="print_bg"><img src="image/print_bg.jpg" alt=""></div><div class="page">';
html += '<span class="num">' + "No." + app_idx + '</span>';
html += '<h1>인쇄할 내용</h1>';
html += '</div>';
obj.html = html;
return obj;
}
//실제 인쇄창 팝업
function reportPrint(param){
const setting = "width=850, height=1100";
const objWin = window.open('', 'print', setting);
objWin.document.open();
objWin.document.write('<html><head><title>인쇄할 내용</title>');
objWin.document.write('<link rel="stylesheet" type="text/css" href="css/print.css"/>');
objWin.document.write('</head><body>');
objWin.document.write(param.html);
objWin.document.write('</body></html>');
objWin.focus();
objWin.document.close();
//브라우저별로 윗 소스가 실행되기 전에 마무리지어버리는 경우가 있으므로 시간여유를 줌
setTimeout(function(){objWin.print();objWin.close();}, 1000);
}
반응형
'개발 이야기 > Javascript & jQuery' 카테고리의 다른 글
javascript 쿠키를 사용해서 스크롤 유지 (0) | 2020.03.26 |
---|---|
즐겨찾기 등록 크로스 브라우징 소스 (0) | 2020.02.05 |
PC or Mobile 접속 판별 소스 (0) | 2020.02.05 |
Event.isTrusted (0) | 2020.02.05 |
remodal is not a function 해결 (0) | 2020.01.14 |