1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
$(function () { //定义打印前事件 var beforePrint = function () { console.log("打印前"); }; //定义打印后事件 var afterPrint = function () { console.log("打印后"); app.post('ba.service.CompanyService', 'updateCompany', { 'companyId': companyId, "autoRegStateCode":"40" }) .then(function (res) { }); } //监听window状态 if (window.matchMedia) { var mediaQueryList = window.matchMedia('print'); //为印添加事件 mediaQueryList.addListener(function (mql) { if (mql.matches) { beforePrint(); } else { afterPrint(); } }); } //打印前事件 window.onbeforeprint = beforePrint; //打印后事件 window.onafterprint = afterPrint; //执行打印 $(".print").click(function () { $(".print").hide() var newstr = document.getElementById("printPage").innerHTML; window.print(); $(".print").show() }) }); |
from:https://codeleading.com/article/96272527602/#google_vignette