📅  最后修改于: 2022-03-11 15:01:47.745000             🧑  作者: Mango
function beforePrint() {
console.log('Do something special before print');
}
function afterPrint() {
console.log('Do something after print');
}
if (window.matchMedia) {
window.matchMedia('print').addListener(function (mql) {
if (mql.matches) {
beforePrint();
}
else {
afterPrint();
}
});
}
// For IE, does not attach in browsers that do not support these events
window.addEventListener('beforeprint', beforePrint, false);
window.addEventListener('afterprint', afterPrint, false);