web api event
Window: beforeprint event
The beforeprint event is fired when the associated document is about to be printed or previewed for printing.
The afterprint and beforeprint events allow pages to change their content before printing starts (perhaps to remove a banner, for example) and then revert those changes after printing has completed. In general, you should prefer the use of a @media print CSS at-rule, but it may be necessary to use these events in some cases.
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("beforeprint", (event) => { })
onbeforeprint = (event) => { }
Event type
A generic Event.
Examples
Using addEventListener():
window.addEventListener("beforeprint", (event) => {
console.log("Before print");
});
Using the onbeforeprint event handler property:
window.onbeforeprint = (event) => {
console.log("Before print");
};
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- Related events:
afterprint