내일을 위한 오늘
JS#1. Print a specific part of a webpage with javascript 본문
반응형
1. Printing using window.onbeforeprint and window.onafterprint.
var prtContent; // The content you want to print
var initBody; // Original web page body content
function startPrint (div_id) {
prtContent = document.getElementById(div_id);
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
window.print();
}
function beforePrint(){
initBody = document.body.innerHTML;
document.body.innerHTML = prtContent.innerHTML;
}
function afterPrint(){
document.body.innerHTML = initBody;
}
<button onclick="startPrint('your div id');">print</button>
2. Printing using pop-up.
var prtCtnt = document.getElementById("your div id");
var prtOption = 'left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0';
var WinPrint = window.open('', '', prtOption);
WinPrint.document.write(prtCtnt.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
source : https://stackoverflow.com/questions/12997123/print-specific-part-of-webpage
728x90
반응형
'IT·컴퓨터 > javascript' 카테고리의 다른 글
[웹개발#8] javascript 공지사항 텍스트 세로 롤링 (0) | 2022.08.31 |
---|---|
JS#1. 웹페이지의 특정 부분만 인쇄하고 싶을 때 (0) | 2022.05.31 |
Comments