HTML | onafterprint Event Attribute
The onafterprint attribute works when a page has started printing, or if the print dialogue box has been closed. This attribute is used together with the onbeforeprint attribute.
Syntax:
<element onafterprint = "script">
Attribute Value: This attribute contains single value script which works when onafterprint event attribute called. This attribute is associated with <body> tag.
Note: This attribute is new in HTML 5.
Example:
<!DOCTYPE html> <html> <head> <title>title attribute</title> <style> body { text-align:center; } h1 { color:green; } </style> </head> <body onafterprint="myFunction()"> <h1>GeeksforGeeks</h1> <h2>onafterprint attribute</h2> <!-- The script run when page will print --> <script> function myFunction() { alert("This document is now being printed"); } </script> </body> </html> |
Output:

Supported Browsers: The browser supported by onafterprint attribute are listed below:
- Chrome 63.0 and above
- Internet Explorer
- Firefox
- Safari: Not supported
- Opera: Not supported
Recommended Posts:
- HTML | oncontextmenu Event Attribute
- HTML | onunload Event Attribute
- HTML | onwheel Event Attribute
- HTML | onmouseover Event Attribute
- HTML | onkeydown Event Attribute
- HTML | ondrag Event Attribute
- HTML | ontoggle Event Attribute
- HTML | ondragend Event Attribute
- HTML | onreset Event Attribute
- HTML | onkeyup Event Attribute
- HTML | onresize Event Attribute
- HTML | ondragleave Event Attribute
- HTML | onchange Event Attribute
- HTML | oninput Event Attribute
- HTML | ondragenter Event Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



