이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 참여해서 번역을 마치도록 도와 주세요!
English (US)의 문서도 읽어보세요.

The onbeforeprint property of the WindowEventHandlers mixin is the EventHandler for processing beforeprint events for the current window. These events are raised before the print dialog window is opened.

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, you should prefer the use of an @media print CSS at-rule, but it may be necessary to use these events in some cases.

Syntax

window.addEventListener("beforeprint", function(event) { ... });
window.onbeforeprint = function(event) { ... };

Polyfill

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 63Edge Full support YesFirefox Full support 6IE Full support YesOpera Full support 50Safari No support NoWebView Android Full support 63Chrome Android Full support 63Edge Mobile Full support YesFirefox Android ? Opera Android Full support 50Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also