網頁打印事件的監聽


這個功能沒有使用過,網上看到的,記錄一下

 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