这个功能没有使用过,网上看到的,记录一下
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;