Execute a JavaScript when a page is about to be printed:
The onbeforeprint event is not supported in Safari and Opera. </p>
<!DOCTYPE html> <html> <body onbeforeprint="myFunction()"> <h1>Try to print this document</h1> <p id="demo"></p> <script> function myFunction() {//from w w w . j av a2 s . c o m document.getElementById("demo").innerHTML = "You are about to print this document!"; } </script> </body> </html>
The onbeforeprint event occurs when a page is about to be printed.
The onbeforeprint event is the opposite of the onafterprint event.
The onbeforeprint event is not supported in Safari and Opera.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <body> |