HTML | onbeforeprint Event Attribute
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.
Syntax:
<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.
Example:
<!DOCTYPE html> <html> <head> <title>onbeforeprint attribute</title> <style> body { text-align:center; } h1 { color:green; } </style> </head> <body onbeforeprint="myFunction()"> <h1>GeeksforGeeks</h1> <h2>onbeforeprint attribute</h2> <!-- The script run when page will ready to print --> <script> function myFunction() { alert("This document is ready to be printed"); } </script> </body> </html> |
Output:

Supported Browsers: The browser supported by onbeforeprint attribute are listed below:
- Chrome 63.0 and above
- Internet Explorer
- Firefox
- Safari: Not supported
- Opera: Not supported
Recommended Posts:
- HTML | DOM onbeforeprint Event
- HTML | onunload Event Attribute
- HTML | oncontextmenu Event Attribute
- HTML | onwheel Event Attribute
- HTML | onmouseover Event Attribute
- HTML | onkeydown Event Attribute
- HTML | ondrag Event Attribute
- HTML | ontoggle Event Attribute
- HTML | ondragend Event Attribute
- HTML | onkeyup Event Attribute
- HTML | onreset Event Attribute
- HTML | onresize Event Attribute
- HTML | onchange Event Attribute
- HTML | oninput Event Attribute
- HTML | ondragenter Event Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



