Skip to content
Related Articles

Related Articles

HTML | onafterprint Event Attribute

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 17 Mar, 2022

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.


<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.


<!DOCTYPE html>
        <title>title attribute</title>
            body {
            h1 {
    <body onafterprint="myFunction()">
        <h2>onafterprint attribute</h2>
        <!-- The script run when page will print -->
            function myFunction() {
                alert("This document is now being printed");


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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!