HTML onafterprint Event Attribute
The HTML onafterprint Event 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. This attribute is typically associated with the window or document element and is part of the WindowEventHandlers interface.
Basically, it is fired after a document is successfully printed or previewed and is useful for executing actions specifically intended for post-printing scenarios.
Syntax:Â
<element onafterprint = "script">
Supported Tags:
Attribute Value:
- This attribute contains a single value which works when an event attribute is called. This attribute is associated with <body> tag.
Example 1:Â In this example, we will see the implementation of onafterprint Event Attribute.
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:Â
Output
Example 2:Â In this example, we will see the implementation of onafterprint Event Attribute.
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() {
console.log("This document is now being printed")
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Opera 15 and above
- Safari 4 and above
Last Updated :
21 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...