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.


  • 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>
        <title>Wikitechy onBeforePrint attribute</title>
 <body onbeforeprint="onBeforePrint()">
        <h1>Wikitechy HTML onbeforeprint Attribute</h1>
        <h4>Try to print this page</h4>
        <p>Press Ctrl+P to print</p>
            function onBeforePrint()
             alert("About to print this document!");

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

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.