I have a button on my page called "Print". clicking on which will trigger a jQuery function.
I need to call the same jQuery function when user hits Alt+f+p or ctrl+p
How do I do that?
I tried to do that with matchMedia but no luck
if (window.matchMedia('print').matches) {
alert("print using browser");
}
There is not a standard way to do that as far as I know.
IE and FF offer own function calls,
In IE there are the nonstandard window.onBeforePrint() and window.onAfterPrint() event listeners. There isn't a non-IE way to do it that I know of, however.
Firefox 6 now supports beforeprint and afterprint https://developer.mozilla.org/en/Printing#Detecting_print_requests
A universally working solution might be to just listen for CMD+P.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With