Window: sự kiện afterprint
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2019.
The afterprint event is fired after the associated document has started printing or the print preview has been closed.
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 a @media print CSS at-rule, but it may be necessary to use these events in some cases.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc thiết lập thuộc tính trình xử lý sự kiện.
addEventListener("afterprint", (event) => { })
onafterprint = (event) => { }
Kiểu sự kiện
Một Event chung.
Ví dụ
Sử dụng addEventListener():
window.addEventListener("afterprint", (event) => {
console.log("After print");
});
Using the onafterprint event handler property:
window.onafterprint = (event) => {
console.log("After print");
};
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # event-afterprint> |
| HTML> # handler-window-onafterprint> |
Tính tương thích trên trình duyệt
Xem thêm
- Related events:
beforeprint