var beforePrint = function() {
console.log('beforePrint');
};
var afterPrint = function() {
console.log('afterPrint');
};
if (window.matchMedia) { //返回一个新的 MediaQueryList 对象,表示指定的媒体查询字符串解析后的结果。
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
获取window.print()的确认和取消事件
最新推荐文章于 2024-01-07 12:15:56 发布