Safari的window.matchMedia处理程序未调用 [英] Safari window.matchMedia handler not called

查看:99
本文介绍了Safari的window.matchMedia处理程序未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发生afterPrint时,我需要执行doSomethingFunc.我的代码在所有浏览器上都能正常运行,但当前的Safari版本(OSX上的Safari 10.1和iOS 10.3上的Safari浏览器)除外.这两个浏览器似乎没有调用事件侦听器(至少用于打印).

I need to execute doSomethingFunc, when afterPrint happens. My code is working fine on all browsers, except the current Safari-Versions (Safari 10.1 on OSX and the Safari Browser from iOS 10.3). It seems that the event listeners (at least for print) are not called for these two browsers.

const mediaQueryPrint = window.matchMedia('print');
mediaQueryPrint.addListener((mql) => {
    if (!mql.matches) {
        setImmediate(doSomethingFunc);
    }
});

window.print();

上面的代码与OSX Safari 9.1.2和iOS 10.2中的Safari完美配合. 但是当前版本中没有.

The code above works perfectly with OSX Safari 9.1.2 and Safari from iOS 10.2. But not with the current versions.

有人注意到类似的东西吗?还是我必须针对当前的Safari版本改进代码?

Has somebody noticed something similar? Or do I have to improve my code for the current Safari versions?

我的猜测是,这是一个Safari错误,因为Safari 10.1中有相应的说明

My guess is, that this is a Safari bug, since there is a corresponding note in the Safari 10.1 changelog chapter Accessability.

推荐答案

您不想打给您

        setImmediate(doSomethingFunc);

何时

    mql.matches

是真的吗?为何 '!'然后呢?

is True? Why the '!' then?

这篇关于Safari的window.matchMedia处理程序未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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