javascript - window.matchMedia('print') failing in Firefox and IE -
i have print button launches print functionality on webpage. button hides user clicks on , shows if user done printing or presses close in print window. works fine in chrome failing in firefox , ie.
<input type="button" onclick="launchprint()" value= "print me" /> function launchprint(){ $(".print-box").hide(); window.print(); } (function() { if (window.matchmedia) { var mediaquerylist = window.matchmedia('print'); mediaquerylist.addlistener(function(mql) { if (!mql.matches) { $(".print-box").show(); } }); } }());
any suggestions may missing?
unfortunately, on same problem , did research. seems bug exists on recents version of ff , ie still , hasn't been fixed.
you can check out bug firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=774398
i found person having same issue , hasn't satisfying answer: https://social.technet.microsoft.com/forums/office/en-us/bc3ca05e-b4ef-425b-8bbd-d3f700a8c85e/windowmatchmedia-not-firing-for-print-in-ie?forum=ieitprocurrentver
if ever come accross solution, edit this.
i use same code exemple highchart resize before printing:
function printupdate() { jquery.each(highcharts.charts, function(index, value){ value.reflow(); }); }; var mediaquerylist = window.matchmedia('print'); if(navigator.appversion.indexof("msie 8.")!==-1)//for ie8 { document.attachevent(function (mql){printupdate();}, mediaquerylist); } else { if (window.matchmedia) { mediaquerylist.addlistener(function (mql) { if (mql.matches) { printupdate(); } }); } } window.onbeforeprint = printupdate;
this work fine in chrome. ff , ie11 won't fire event.
Comments
Post a Comment