HTML event attribute onbeforeprint

The onbeforeprint attribute event is triggered when a page is about to print or before the print dialogbox appears.

What's new in HTML5

The onbeforeprint attribute is new in HTML5.


<element onbeforeprint="script or javascript function name">

Supported Tags


Browser compatibility

onbeforeprint Yes Yes Yes Yes Yes


<!DOCTYPE html>
<body onbeforeprint="myFunction()">
<!--from  w w w  .j  ava  2 s. c om-->
<h1>Try to print this document</h1>

function myFunction() {


Click to view the demo