当相关联的文档即将打印或预览以进行打印时,将触发beforeprint事件。
基本信息
- Specification
- HTML5
- 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 | Status |
---|---|
HTML Living Standard | Living Standard |
浏览器兼容性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.