x
 
<!DOCTYPE html>
<html>
<body>
<p>This example uses the HTML DOM to assign an "onafterprint" event to a body element.</p>
<h1>请尝试打印此文档</h1>
<p><b>提示:</b>键盘快捷键,例如 Ctrl+P,可设置要打印的页面。</p>
<p><b>注释:</b>Safari 和 Opera 不支持 onafterprint 事件。</p>
<p><b>注释:</b>在 IE 中,onafterprint 事件发生在打印对话框之前,而不是之后。</p>
<script>
document.getElementsByTagName("BODY")[0].onafterprint = function() {myFunction()};
function myFunction() {
  alert("This document is now being printed");
}
</script>
</body>
</html>