revision:
The attribute fires when a page is about to be printed or before the print dialogue box appears. The onbeforeprint attribute is often used together with the onafterprint attribute.
The onbeforeprint attribute is part of the <event attributes> and can be used on the following element:<body>.
<element onbeforeprint="script"></element>
script: the script to be run on onbeforeprint
Keyboard shortcuts, such as Ctrl+P sets the page to print.
<body onbeforeprint="myFunction()"> <h4>Try to print this document</h4> <p class="spec">Keyboard shortcuts, such as Ctrl+P sets the page to print.</p> </body> <script> function myFunction() { alert("You are about to print this document!"); } </script>