Nos bénévoles n'ont pas encore traduit cet article en Français. Inscrivez-vous et aidez-nous à réaliser cette tâche !
Vous pouvez également lire cet article en English (US).

 

Summary

The property onbeforeprint sets and returns the onbeforeprint event handler code for the current window.

Syntax

window.onbeforeprint = event handling code

Notes

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

Specification Status Comment
HTML Living Standard
The definition of 'onbeforeprint' in that specification.
Living Standard  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support63 Yes6 Yes50 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support6363 Yes ?50 ? ?

See also

 

Étiquettes et contributeurs liés au document

Étiquettes : 
Dernière mise à jour par : Jonathan_Watt,