<html>
<body>
<p>本使用 addEventListener() 方法将 "beforeprint" 事件附加到 window 对象。</p>
<h1>请尝试打印此文档</h1>
<p><b>提示:</b>键盘快捷键,例如 Ctrl+P,可设置要打印的页面。</p>
<p><b>注释:</b>Safari 和 Opera 不支持 onbeforeprint 事件。</p>
<script>
window.addEventListener("beforeprint", myFunction);
function myFunction() {
alert("You are about to print this document!");
}
</script>
</body>
</html>