Safari window.matchMedia handler not called

▼魔方 西西 提交于 2019-12-23 07:38:19

问题


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();

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

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

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


回答1:


Did you not want to call

        setImmediate(doSomethingFunc);

when

    mql.matches

is True? Why the '!' then?



来源:https://stackoverflow.com/questions/43386499/safari-window-matchmedia-handler-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!