网页打印事件的监听


这个功能没有使用过,网上看到的,记录一下

 1 var beforePrint = function() {
 2     console.log('Functionality to run before printing.');
 3 };
 4 
 5 var afterPrint = function() {
 6     console.log('Functionality to run after printing');
 7 };
 8 
 9 if (window.matchMedia) {
10     var mediaQueryList = window.matchMedia('print');
11     mediaQueryList.addListener(function(mql) {
12         if (mql.matches) {
13             beforePrint();
14         } else {
15             afterPrint();
16         }
17     });
18 }
19 
20 window.onbeforeprint = beforePrint;
21 window.onafterprint = afterPrint;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM