onbeforeprint和onafterprint在Chrome和IE中不起作用? [英] onbeforeprint and onafterprint is not working in Chrome and IE?
本文介绍了onbeforeprint和onafterprint在Chrome和IE中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的项目中使用打印(使用HTML和javascript)。在mozilla onbeforeprint和onafterprint工作正常但没有使用chrome。
I am using printing in my project (Using HTML and javascript). In mozilla onbeforeprint and onafterprint is working properly but not working in chrome.
推荐答案
对Chrome来说有用的是检查'matchmedia'在'窗口'中如下:
What works for Chrome is to check for 'matchmedia' in 'window' as in:
if ('matchMedia' in window) {
window.matchMedia('print').addListener(function (media) {
//do before-printing stuff
});
} else {
window.onbeforeprint = function () {
//do before-printing stuff
}
}
这篇关于onbeforeprint和onafterprint在Chrome和IE中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文