HTML5 onbeforeprintEvent Attribute

HTML 事件属性HTML Event Attributes

Examples

Execute JavaScript when the page is set to print, but before the print dialog box appears:

<body onbeforeprint="printmsg()">

Try it Yourself »

Browser Support

Event
onbeforeprint 63 Yes Yes 13 50

Definition and Usage

The onbeforeprint attribute is triggered when the user sets the page to print, but before the print dialog box appears.

Tip:The onbeforeprint attribute is usually used together with theonafterprintattribute.


Differences between HTML 4.01 and HTML5

The onbeforeprint attribute is new in HTML5.


Syntax

<element onbeforeprint="script">

Attribute Values

Value Description
script Script to be executed in onafterprint.


HTML 事件属性HTML Event Attributes Other Extensions