16

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.

m4lt3
  • 465
  • 2
  • 15
  • Yes I've experience the same thing - Turns out (In my case) that it fires the handler just fine if the print is within 1 page. If the print is more than one page, it gets ignored completely. I haven't found any bug reports on it yet though. – Rolchau May 17 '17 at 17:47
  • yeah, I guess this feature is not used very often. I would be very glad, if you wrote a bug report on bugreport.apple.com. I did the same. Sadly apple is very intransparent with its bugs, so we do not know if apple noticed it already. – m4lt3 May 19 '17 at 07:42

1 Answers1

-1

Did you not want to call

        setImmediate(doSomethingFunc);

when

    mql.matches

is True? Why the '!' then?

oopoopoop
  • 61
  • 8
  • if you say `!mql.matches` you are doing stuff during the afterPrint-Event and if you say `mql.matches` you are doing stuff during the beforePrint-Event. – m4lt3 Apr 27 '17 at 07:43
  • just asking. your original question didn't state that you want the afterPrint-Event. Thanks for the down-vote and now I learn more about how SO works. – oopoopoop Apr 27 '17 at 09:04