onbeforeprint
特性为
WindowEventHandlers
混合
EventHandler
为处理
beforeprint
events for the current window. These events are raised before the print dialog window is opened.
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.
window.addEventListener("beforeprint", function(event) { ... });
window.onbeforeprint = function(event) { ... };
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');
}
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'onbeforeprint' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onbeforeprint
|
Chrome 63 | Edge 12 | Firefox 6 | IE Yes | Opera 50 | Safari 13 | WebView Android 63 | Chrome Android 63 | Firefox Android ? | Opera Android 46 | Safari iOS 13 | Samsung Internet Android 8.0 |
完整支持
兼容性未知