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.

HTML 5

  • 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>
<html>
    <head>
        <title>Wikitechy HTML onafterprint Attribute</title>
    </head>
    <body onafterprint="OnAfterPrint()">
        <h1>Wikitechy HTML onafterprint Attribute</h1>
        <p>Press Ctrl+P to print the page.</p>
        <script>
            function OnAfterPrint(){
                alert("This document is now being printed");
                }
        </script>
    </body>
</html>

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