In JavaScript, using the addEventListener()
method:
object.addEventListener("beforeprint",
myScript);
The beforeprint event is not supported in Safari and Opera.
This example uses the addEventListener()
method to attach a "beforeprint" event to the window object.
<!DOCTYPE html> <html> <body> <h1>Try to print this document</h1> <p id="demo"></p> <script> window.addEventListener("beforeprint", myFunction); function myFunction() {/*from w w w . j a va2s .c om*/ 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> |