In JavaScript:
object.onbeforeprint = function(){
myScript};
This example uses the HTML DOM to assign an "onbeforeprint" event to a body element.
<!DOCTYPE html> <html> <body> <h1>Try to print this document</h1> <p id="demo"></p> <script> document.getElementsByTagName("BODY")[0].onbeforeprint = function() {myFunction()}; function myFunction() {/*from ww w.j a v a 2s. c o m*/ document.getElementById("demo").innerHTML = "You are about to print this document!"; } </script> </body> </html>
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <body> |