Safari handler window.matchMedia not called

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

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

This code works great with OSX Safari 9.1.2 and Safari from iOS 10.2. But not with current versions.

Has anyone noticed something like this? Or do I need to improve the code for the current version of Safari?

I assume this is a Safari error, since a note is available in the Safari 10.1 changelog section.

+8
javascript safari ios media-queries matchmedia
source share
1 answer

You do not want to call

  setImmediate(doSomethingFunc); 

when

  mql.matches 

- true? Why '!' then?

-one
source share

All Articles