Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM onafterprint Event

  • Last Updated : 30 Jul, 2021

The DOM onafterprint event occurs when a web page has started printing or if the print dialogue box has been closed.
Supported Tags 

  • <body>

Syntax: 
 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • HTML: 
     
<element onafterprint="myScript">
  • JavaScript: 
     
object.onafterprint = function(){myScript};
  • In JavaScript, using the addEventListener() method: 
     
object.addEventListener("afterprint", myScript);

Example: 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML | DOM onafterprint Event
    </title>
</head>
 
<body>
    <center>
        <h1 style="color:green">
            GeeksforGeeks
        </h1>
         
        <h2>DOM onafterprint Event</h2>
         
         
<p>
            <strong>Tip: </strong>Keyboard
            shortcuts Ctrl+P
        </p>
 
 
        <script>
            window.addEventListener("afterprint", myGeeks);
 
            function myGeeks() {
                alert("Document Printed");
            }
        </script>
    </center>
</body>
 
</html>   

Output: 
 



  • Before Print: 
     

  • After Print: 
     

Supported Browsers: The browsers supported by HTML DOM onafterprint Event are listed below: 
 

  • Google Chrome 63.0
  • Internet Explorer
  • Firefox

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :