var beforePrint = function () {
//alert('Functionality to run before printing.');
//开始打印
};
var afterPrint = function () {
//alert('Functionality to run after printing');
//结束打印
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function (mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
本文介绍了一个使用JavaScript在网页打印前后执行特定功能的示例,通过`window.matchMedia`监听打印媒体查询,实现beforePrint和afterPrint函数的调用。

5578

被折叠的 条评论
为什么被折叠?



