HTML onbeforeprint 이벤트 속성은 페이지가 인쇄되려고 할 때 또는 HTML 문서에 인쇄 대화 상자가 나타나기 전에 트리거됩니다.
구문
다음은 구문입니다 -
<tagname onbeforeprint=”script”></tagname>
HTML onbeforeprint 이벤트 Attribute의 예를 살펴보겠습니다-
예시
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background-color: #FBAB7E;
background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
text-align: center;
padding: 20px;
}
p {
font-size: 1.1rem;
}
</style>
</head>
<body onbeforeprint="get()">
<h1>HTML onbeforeprint Event Attribute Demo</h1>
<p>I'm a paragraph HTML element with some dummy text.</p>
<p style="color:#db133a;">Now try to print this document.</p>
<div class="show"></div>
<script>
function get() {
document.body.style.background = "lightblue";
}
</script>
</body>
</html> 출력

이제 ctrl + p를 사용하여 문서를 인쇄하고 onbeforeprint 이벤트 속성이 어떻게 작동하는지 관찰하십시오.
