THE WORLD'S LARGEST WEB DEVELOPER SITE

onbeforeprint Event

❮ DOM Events ❮ Event Object

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 (before the print dialogue box appears).

Tip: The onbeforeprint event is the opposite of the onafterprint event.


Browser Support

Event
onbeforeprint 63 Yes Yes Not supported Not supported

Syntax

In HTML:

<element onbeforeprint="myScript">
Try it Yourself »

In JavaScript:

object.onbeforeprint = function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("beforeprint", myScript);
Try it Yourself »

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags:  <body>
DOM Version: Level 3 Events

❮ DOM Events ❮ Event Object