In JavaScript, using the addEventListener()
method:
object.addEventListener("afterprint",
myScript);
This example uses the addEventListener()
method to attach an "afterprint" event to the window object.
<!DOCTYPE html> <html> <body> <h1>Try to print this document</h1> <p id="demo"></p> <script> window.addEventListener("afterprint", myFunction); function myFunction() {/*w w w . j a va 2s . com*/ document.getElementById("demo").innerHTML = "This document is now being printed"; } </script> </body> </html>