onbeforeprint Event
Example
Execute a JavaScript when a page is about to be printed:
<body onbeforeprint="myFunction()">
Try it Yourself »
Definition and Usage
The onbeforeprint
event occurs when a page is about to be printed.
The onbeforeprint
event occurs before a print dialogue box opens.
Note
The browser fires onafterprint
and
onbeforeprint
so that notes, explanations and comments can be added
to the printing process.
See Also:
Syntax
In JavaScript, using the addEventListener() method:
object.addEventListener("beforeprint", myScript);
Try it Yourself »
Technical Details
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <body> |
DOM Version: | Level 3 Events |
Browser Support
onbeforeprint
is a DOM Level 3 (2004) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |