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.
Applicable:
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:
html
<!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 >
< 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
- Edge 12
- Internet Explorer 9
- Firefox 6
- Safari 13
- Opera 50
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 Aug, 2022
Like Article
Save Article