프린트 출력후 onafterprint 자바스크립트로 액션 처리 방법
2020.04.27 09:03
브라우저에서 프린트 창이 오픈된 후에, 액션 처리방법이다.
결과물을 출력을 했는지 안했는지는 하드웨어 제어를 통해서만 알 수 있다.
사용자가 결과물을 출력한후, 메세지 창을 통해서 출력 결과 여부를 묻고 처리하는 방식이다.
<script type="text/javascript">
function Printed() {
var er = confirm("Do you want to record that the packet was printed?"); // 메세지창 출력
var msg = "OK"; // 부모창에 전달할 결과 값
var onPrint = window.opener.document.getElementById('onPrint'); // 부모창 엘리먼트 ID
if (er == true){
onPrint.value = msg; // "확인"인 경우 결과 값 부모창에 전달
onPrint.style.display = "block"; // 부모창 스타일 지정
} else {
onPrint.value = ''; // "취소"인 경우 결과 값 부모창에 전달
window.opener.document.getElementById('Print-'+srl).innerText = 'Not Yet Printed!'; // "취소"인 경우 출력되지 않았음을 부모창에 출력
}
window.close(); // 프린트창 닫기
}
document.getElementsByTagName("BODY")[0].onafterprint=function(){Printed();}; // 프린트창 출력된 후 액션 처리
</script>