• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 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新属性。

    属性值

    描述
    scriptonafterprint中执行的脚本。

    实例

    在页面设置打印,但在打印对话框出现前执行
    javascript:<body onbeforeprint="printmsg()">

    上篇:onafterprint

    下篇:onload