代码编辑器:
x
1
<p>演示了如何使用 HTML DOM 向 body 元素添加 "onbeforeprint" 事件</p>
2
<h1>尝试打印文档</h1>
3
<p><b>提示:</b> 快捷键,如 Ctrl+P 可以设置页面打印</p>
4
<p><b>注意:</b> 只有 Internet Explorer 和 Firefox 浏览器支持 onbeforeprint 事件</p>
5
<script>
6
document.getElementsByTagName("BODY")[0].onbeforeprint = function() {myFunction()};
7
function myFunction() {
8
alert("即将开始打印该文档");
9
}
10
</script>
11