HTML onafterprint Event Attribute


The event attribute onafterprint occurs when a page is printed, namely when the print dialog box closes. The onafterprint attribute is often used in conjunction with the onbeforeprint attribute.


<element onafterprint="script">


  • scriptThe name of the script to use when the event has been triggered.


<!DOCTYPE html>
<meta charset="utf-8">
<title>onafterprint event</title>
<body onafterprint="test()">
<h1>Try to print this document.</h1>
<p><b>Tip:</b>The keyboard shortcut Ctrl + P prints the page.</p>
<p><b>Note:</b>The onafterprint event is supported only in Internet Explorer and Firefox.</p>
function test() {
    alert("This document will now be printed.");

Supported Tags


Browser Support

Explorer Edge Chrome Firefox Opera Safari
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung