- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML onbeforeprint Event Attribute
The HTML onbeforeprint event attribute is triggered when a page is about to be printed or before the print dialog box appears in the HTML document.
Syntax
Following is the syntax −
<tagname onbeforeprint=”script”></tagname>
Let us see an example of HTML onbeforeprint event Attribute−
Example
<!DOCTYPE html> <html> <head> <style> body { color: #000; height: 100vh; background-color: #FBAB7E; background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%); text-align: center; padding: 20px; } p { font-size: 1.1rem; } </style> </head> <body onbeforeprint="get()"> <h1>HTML onbeforeprint Event Attribute Demo</h1> <p>I'm a paragraph HTML element with some dummy text.</p> <p style="color:#db133a;">Now try to print this document.</p> <div class="show"></div> <script> function get() { document.body.style.background = "lightblue"; } </script> </body> </html>
Output
Now try to print the document by using ctrl + p and observe how onbeforeprint event attribute works.
- Related Articles
- HTML onblur Event Attribute
- HTML onclick Event Attribute
- HTML onchange Event Attribute
- HTML oncopy Event Attribute
- HTML oncut Event Attribute
- HTML oncontextmenu Event Attribute
- HTML ondrag Event Attribute
- HTML onfocus Event Attribute
- HTML oninput Event Attribute
- HTML oninvalid Event Attribute
- HTML onpaste Event Attribute
- HTML onresize Event Attribute
- HTML onreset Event Attribute
- HTML onsubmit Event Attribute
- HTML onscroll Event Attribute

Advertisements