onbeforeprint() and onafterprint() equivalent for non IE browsers

Many browsers now support window.matchMedia. This API allows you to detect when CSS media queries go into effect (e.g., rotating the screen or printing the document). For a cross-browser approach, combine window.matchMedia with window.onbeforeprint/window.onafterprint. The following may result in multiple calls to beforePrint() and afterPrint() (for example, Chrome fires the listener every time the print … Read more