WindowEventHandlers.onbeforeprint

翻译不完整。 请帮助我们翻译这篇文章!

WindowEventHandlersonbeforeprint属性是用于处理当前窗口的beforeprint事件的EventHandler。在打开打印对话窗口之前会触发这些事件。
beforeprintafterprint事件允许网页在打印开始前更改他们的内容(例如:可能是删除一个横幅),然后在打印完成后恢复这些更改。通常,您应该更喜欢使用@media printCSS规则,但是在某些情况下可能有必要使用这些事件。

语法

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

范例

Safari没有实现这些事件,但是您可以使用创建与beforeprint事件等效的结果window.matchMedia('print')

var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
  if(mql.matches) {
    console.log('webkit equivalent of onbeforeprint');
  }
});

规范

规范 状态 注解
HTML Living Standard
onbeforeprint
Living Standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onbeforeprintChrome Full support 63Edge Full support 12Firefox Full support 6IE Full support YesOpera Full support 50Safari Full support 13WebView Android Full support 63Chrome Android Full support 63Firefox Android ? Opera Android Full support 46Safari iOS Full support 13Samsung Internet Android Full support 8.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

参阅