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




Onbeforeprint attribute in html

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

  • The onbeforeprint attribute is triggers before the print dialog box appears.
  • The onbeforeprint attribute is a part of the Event Attributes.

Syntax for low attribute in HTML:

<body onbeforeprint="script">

Differences between HTML 4.01 and HTML5 for onbeforeprint attribute:

HTML 4.01

  • The onbeforeprint attribute has not been defined.

HTML 5

  • The onbeforeprint attribute is added newly.

Applies To:

Element Attribute
<body> onbeforeprint

Attribute Values:

Value Description
script The script can run on onbeforeprint

Sample Coding for onbeforeprint Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
        <head>
        <title>Wikitechy onBeforePrint attribute</title>
        </head>
 <body onbeforeprint="onBeforePrint()">
        <h1>Wikitechy HTML onbeforeprint Attribute</h1>
        <h4>Try to print this page</h4>
        <p>Press Ctrl+P to print</p>
        <script>
            function onBeforePrint()
            {
             alert("About to print this document!");
            }
        </script>
</body>
</html>

Code Explanation for onbeforeprint Attribute in HTML:

onbeforeprint Attribute Code Explanation

  1. The onbeforeprint attribute is used to define when a page is about to be printed.
  2. Before the printer configuration settings, the function OnBeforePrint () will be called the alert message displaying” About to print this document”.

Output for onbeforeprint Attribute in HTML:

onbeforeprint Attribute Tag Output

  1. When we press CTRL+P to print the page, the alert box has been displayed with the message” About to print this document”.
  2. onbeforeprint1 Attribute Tag Output

  3. After clicking the ok button in the alert box, the print dialog box has been appeared.

Browser Support for onbeforeprint Attribute in HTML:

No Yes Yes No No

Related Searches to onbeforeprint Attribute in html