HTML onafterprint Event Attribute

Description

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.

Syntax

<element onafterprint="script">

Values

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

Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>onafterprint event</title>
</head>
<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>
<script>
function test() {
    alert("This document will now be printed.");
}
</script>
</body>
</html>

Supported Tags

<body>,

Browser Support

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