Window: afterprint event

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.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("afterprint", (event) => { })

onafterprint = (event) => { }

Event type

A generic Event.

Examples

Using addEventListener():

js
window.addEventListener("afterprint", (event) => {
  console.log("After print");
});

Using the onafterprint event handler property:

js
window.onafterprint = (event) => {
  console.log("After print");
};

Specifications

Specification
HTML
# event-afterprint
HTML
# handler-window-onafterprint

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
afterprint event
Chrome – Full support
Chrome 63 (Release date: 2017-12-06)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 6 (Release date: 2011-08-16)
footnote Full support
Opera – Full support
Opera 50 (Release date: 2018-01-04)
footnote Full support
Safari – Full support
Safari 13 (Release date: 2019-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 63 (Release date: 2017-12-05)
footnote Full support
Firefox for Android – Full support
Firefox for Android 6 (Release date: 2011-08-16)
footnote Full support
Opera Android – Full support
Opera Android 46 (Release date: 2018-05-14)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13 (Release date: 2019-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 8 (Release date: 2018-07-18)
footnote Full support
WebView Android – Full support
WebView Android 63 (Release date: 2017-12-05)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13 (Release date: 2019-09-19)
footnote Full support
Deno – No support
Deno
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also