Open In App
Related Articles

HTML | onbeforeprint Event Attribute

Improve Article
Save Article
Like Article

The onbeforeprint attribute works when a page is about to be printed. The alert message display before the print dialogue box appears. The onbeforeprint attribute is used with the onafterprint attribute.
Supported Tags 


<element onbeforeprint = "script">

Attribute Value: This attribute contains single attribute value script and it works when document is about to print. This attribute is supported by <body> tag.


<!DOCTYPE html>
        <title>onbeforeprint attribute</title>
            body {
            h1 {
    <body onbeforeprint="myFunction()">
        <h2>onbeforeprint attribute</h2>
        <!-- The script run when page will ready to print -->
            function myFunction() {
                alert("This document is ready to be printed");


Supported Browsers: The browser supported by onbeforeprint attribute are listed below: 

  • Chrome 63
  • Edge 12
  • Internet Explorer 9
  • Firefox 6
  • Safari 13
  • Opera 50


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Aug, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials