- 0133技术站
- 联系QQ:88526
- QQ交流群

- 微信公众号

定义和用法
onbeforeprint 属性在用户设置页面打印,但在打印对话框出现前触发。
提示: onbeforeprint 属性通常与 onafterprint 属性一起使用。
浏览器支持
目前只有 Internet Explorer 和 Firefox 浏览器支持 onbeforeprint 事件属性。
HTML 4.01 与 HTML5之间的差异
onbeforeprint 属性是HTML5新属性。
语法
<element onbeforeprint="script">
属性值
值 | 描述 |
---|---|
script | onafterprint中执行的脚本。 |
在页面设置打印,但在打印对话框出现前执行 JavaScript :
<!DOCTYPE html> <html> <meta charset="utf-8"> <title>0133技术站(0133.cn)</title> <head> <script> function printmsg() { alert("你现在要打印该文档!"); } </script> </head> <body onbeforeprint="printmsg()"> <h1>打印文档</h1> <p><b>提示:</b> 快捷键, 如 Ctrl+P 设置打印页面。</p> <p><b>注意:</b> 目前只有 Internet Explorer 和 Firefox 浏览器支持 onafterprint 事件属性。</p> </body> </html>
点击 "运行实例" 按钮查看在线实例
推荐手册