English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML5 onafterprint event attribute

Trigger the afterprint event after the associated document has started printing or the print preview has been closed.

HTML Event Attributes

Online Example

Execute JavaScript after the page starts printing or the print dialog is closed:

<!DOCTYPE html>
<html>
<head>
<title>Usage of HTML onafterprint Event Attribute (Basic Tutorial Website oldtoolbag.com)</b>/title>
<script>
function printmsg()
{
    alert("The document is printing");
}
</script>
</head>
<body onafterprint="printmsg()">
<h1>Print document</h1>
<p><b>Tip:</b>/Shortcut keys, such as Ctrl+Set the print page./p>
<p><b>Attention:</Currently, only Internet Explorer and Firefox browsers support the onafterprint event attribute./p>
<p><b>Attention:</b> In the IE browser, the onafterprint attribute executes JavaScript before the print dialog instead of after.</p>
</body>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Note:In IE / In Edge, the onafterprint attribute appears before the print dialog, not after it.

Definition and Usage

The onafterprint attribute is triggered when the page starts printing, or if the print dialog is closed.

Tip: The onafterprint attribute is usually used with the onbeforeprint attribute.

HTML 4.01 with HTML5difference

The onafterprint attribute is an HTML5New Attribute.

Syntax

<element onafterprint="script">

Attribute Value

ValueDescription
scriptScript executed in onafterprint.
HTML Event Attributes