html tutorial - onafterprint Attribute in HTML - html5 - html code - html form

Onafterprint attribute in html

Learn html - html tutorial - Onafterprint attribute in html - html examples - html programs

  • The onafterprint attribute is used to triggers when the page is start printing or the print dialog box has been closed.
  • The onafterprint attribute is a part of the Event Attributes.

Syntax for onafterprint attribute in HTML:

<body onafterprint="script">

Difference between HTML 4.01 and HTML 5 for onafterprint Attribute:

HTML 4.01

  • The onafterprint attribute has not been defined.


  • The onafterprint attribute is added newly.

Applies To:

Element Attribute
<body> onafterprint

onafterprint Attribute Values:

Value Description
script The script can run on onafterprint

Sample Coding for onafterprint Attribute in HTML:

Tryit<!DOCTYPE html>
        <title>Wikitechy HTML onafterprint Attribute</title>
    <body onafterprint="OnAfterPrint()">
        <h1>Wikitechy HTML onafterprint Attribute</h1>
        <p>Press Ctrl+P to print the page.</p>
            function OnAfterPrint(){
                alert("This document is now being printed");

Code Explanation for onafterprint Attribute in HTML:

onafterprint Attribute Code Explanation

  1. Onafterprint attribute is used to specify when the page starts printing and function OnAfterPrint() is called.
  2. After the printer configuration settings, the function OnAfterPrint() will be called the alert message displaying ”This document is now being printed”.

Output for onafterprint Attribute in HTML:

onafterprint Attribute Output

  1. When we press the CTRL+P to print the page, the print dialog box has been appeared.
  2. onafterprint Attribute Output
  3. After clicking the OK button in the print dialog box, the alert box has been displayed with the message ”The document is now being printed”.

Browser Support for onafterprint Attribute in HTML:

No Yes Yes No No

Related Searches to onafterprint Attribute in html

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.