window.matchMedia('print')在Firefox和IE中失败 [英] window.matchMedia('print') failing in Firefox and IE

查看:1421
本文介绍了window.matchMedia('print')在Firefox和IE中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个打印按钮,可以在任何网页上启动打印功能。一旦用户点击该按钮,该按钮就会隐藏,并显示用户是否已完成打印或在打印窗口中关闭。它在Chrome中运行正常,但在Firefox和IE中失败。

I have a print button that launches the print functionality on any webpage. The button hides as soon as the user clicks on it and shows if the user is done printing or presses close in the print window. It works fine in Chrome but is failing in firefox and 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 what I may be missing?

推荐答案

nofollow noreferrer> onprintprint 事件。至少这是由Firefox和IE触发的,所以为了让你的用例可以听到 matchMedia(print)的潜在后卫(以确保事件不会多次触发) / code>和 onafterprint 事件。

You might want to look at the onafterprint event. At least this is triggered by Firefox and IE, so with a potential guard (to make sure the event did not fire multiple times) for your use case you can listen to both the matchMedia("print") and the onafterprint event.

这篇关于window.matchMedia('print')在Firefox和IE中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆