看这里
(function() {
var beforePrint = function() {
console.log('打印前');
};
var afterPrint = function() {
console.log('打印后');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…