English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tag comprehensive list

HTML5 onbeforeprint event property

When the document related to the page is about to be printed or previewed for printing, the beforeprint event is triggered.

HTML 이벤트 속성

Online example

When the page is to be printed, JavaScript is executed :

<!DOCTYPE html>
<html>
<head>
<title>HTML onbeforeprint event property usage(basic tutorial site oldtoolbag.com)</title>
<body onbeforeprint="myFunction()">
<h1>Try to print this document</h1>
<p><b>Tip:</b> Keyboard shortcuts, such as Ctrl+P sets the page to print.</p>
<p><b>Note:</b> The onbeforeprint event is not supported in Safari and Opera.</p>
<script>
function myFunction() {
  alert("You are about to print this document!");
}
</script>
</body>
</html>
테스트해 보세요 ‹/›

브라우저 호환성

IEFirefoxOperaChromeSafari

현재 Internet Explorer와 Firefox 브라우저만이 onbeforeprint 이벤트 속성을 지원합니다.

정의와 사용법

打印页面即将出现(在打印对话框出现之前),将触发onbeforeprint 속성。
참고: onbeforeprint 속성은 onafterprint 속성과 함께 사용되는 경우가 많습니다

HTML 4.01 와 HTML5사이의 차이

onbeforeprint 속성은 HTML5새 속성.

문법

<element onbeforeprint="script">

속성 값

설명
scriptonafterprint에서 실행되는 스크립트.
HTML 이벤트 속성