The property onbeforeprint
sets and returns the onbeforeprint
event handler code for the current window.
window.onbeforeprint = event handling code
The beforeprint
and afterprint
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 content authors should prefer the use of an @media print CSS at-rule, but it may be necessary to use these events in some cases.
The beforeprint
event is raised before the print dialog window is opened.
Safari does not implement these events, but you can create an equivalent result to the beforeprint
event with
.window.matchMedia
('print')
var mediaQueryList = window.matchMedia('print'); mediaQueryList.addListener(function(mql) { if(mql.matches) { console.log('webkit equivalent of onbeforeprint'); } });
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'onbeforeprint' in that specification. | Living Standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 63 | Yes | 6 | Yes | 50 | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 63 | 63 | Yes | ? | 50 | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeprint