onbeforeprint
版本:HTML5
定义和用法
onbeforeprint属性在用户设置页面打印,但在打印对话框出现前触发。
提示:onbeforeprint属性通常与onafterprint属性一起使用。
语法
<element onbeforeprint="script">
浏览器支持
![]() | ![]() | ![]() | ![]() | ![]() |
目前只有 Internet Explorer 和 Firefox 浏览器支持onbeforeprint事件属性。 | ||||
示例
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>www.lanmper.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>
HTML 4.01 与 HTML5之间的差异
onbeforeprint属性是HTML5新属性。
属性值
| 值 | 描述 |
|---|---|
| script | onafterprint中执行的脚本。 |
实例
在页面设置打印,但在打印对话框出现前执行javascript:<body onbeforeprint="printmsg()">





