Sample Coding for onbeforeprint Attribute in HTML:
Tryit<!DOCTYPE html><html><head><title>Wikitechy onBeforePrint attribute</title></head><bodyonbeforeprint="onBeforePrint()"><h1>Wikitechy HTML onbeforeprint Attribute</h1><h4>Try to print this page</h4><p>Press Ctrl+P to print</p><script>functiononBeforePrint()
{
alert("About to print this document!");
}
</script></body></html>
Code Explanation for onbeforeprint Attribute in HTML:
The onbeforeprint attribute is used to define when a page is about to be printed.
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:
When we press CTRL+P to print the page, the alert box has been displayed with the message” About to print this document”.
After clicking the ok button in the alert box, the print dialog box has been appeared.
Browser Support for onbeforeprint Attribute in HTML: