beforeprint
当相关联的文档即将打印或预览以进行打印时,将触发 beforeprint 事件。
基本信息
- Specification
- Interface
-
Event
- Bubbles
-
No
- Cancelable
-
No
- Target
-
DefaultView (
<window>
) - Default Action
-
None
属性
属性 | 类型 | 描述 |
---|---|---|
target 只读 |
EventTarget |
事件目标 (DOM 树中的最顶层目标) |
type 只读 |
DOMString |
时间类型 |
bubbles 只读 |
Boolean |
事件是否冒泡 |
cancelable 只读 |
Boolean |
事件是否可取消 |
样例
使用 addEventListener()
:
window.addEventListener('beforeprint', (event) => {
console.log('Before print');
});
使用 onbeforeprint
事件监听属性:
window.onbeforeprint = (event) => {
console.log('Before print');
};
规范
Specification |
---|
HTML Standard # event-beforeprint |
HTML Standard # handler-window-onbeforeprint |
浏览器兼容性
BCD tables only load in the browser