HTML onbeforeprint Event Attribute
The onbeforeprint event fires when a page is about to be printed before the print dialog box appears. This event can be used to perform actions before printing, such as hiding unnecessary elements or preparing the page for printing.
Syntax:Â
<element onbeforeprint = "script">
Supported TagsÂ
Attribute Value:
This attribute contains the script, this script is to be run on onbeforeprint
Example 1:Â In this example, we will see the implementation of the onbeforeprint Event attribute.
html
<!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 >
< script >
function myFunction() {
alert("This document is ready to be printed");
}
</ script >
</ body >
</ html >
|
Output:Â
Output
Example 2:Â In this example, we will see the implementation of the onbeforeprint Event attribute.
HTML
<!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 >
< script >
function myFunction() {
console.log("This document is ready to be printed")
}
</ script >
</ body >
</ html >
|
Output:
Output
Supported Browsers:
- Google Chrome 63
- Edge 12
- Firefox 6
- Opera 5
- Safari 4
Last Updated :
26 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...