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.

Syntax

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

Supported Tags

<body>

Browser compatibility

onbeforeprint Yes Yes Yes Yes Yes




Example

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

<script>
function myFunction() {
    alert("print");
}
</script>

</body>
</html>

Click to view the demo