HTML onafterprint attribute

HTML onafterprint attribute help us to produce when the page starts printing (or) if the dialog box closes. And it is also known as event attribute.

HTML onafterprint attribute

The attribute consists of  <body> element.

Syntax: <body onafterprint=”script”>

Browser compatibility

This  attribute supports different types of browsers as follows:

  • Chrome
  • Mozilla
  • InternetExplorer

And it was not supported by remaining browsers like Safari and Opera.

Example:

<!DOCTYPE html>
<html>
    <head>
        <title>Freshersnow HTML onafterprint Attribute</title>
    </head>
    <body onafterprint="OnAfterPrint()">
        <h1>Try to print this document</h1>
        <p><b>Tip:</b> Keyboard shortcuts, such as Ctrl+P sets the page to print.</p>
        <p><b>Note:</b> The onafterprint event is not supported in Safari and Opera.</p>
       <p><b>Note:</b> In IE, the onafterprint event occurs before the print dialogue box, instead of after.</p>
        </script>
    </body>
 </html>

Output:

Try to print this document

Tip: Keyboard shortcuts, such as Ctrl+P sets the page to print.

Note: The onafterprint event is not supported in Safari and Opera.

Note: In IE, the onafterprint event occurs before the print dialogue box, instead of after.