Javascript Windows.print() Callback - Determining When A Print Job Completes
Question: Is it possible to add a callback to the windows.print() function? I realize there isn't a native solution, but I was wondering if there is some sort of library that accom
Solution 1:
Seems like you want to listen for the afterprint event
window.addEventListener('afterprint', e =>console.log('Ready for next print job'));
Please note that this has low cross-browser support (FireFox 6+, IE)
The MDN page also tells us that something similar can be achieved in webkit based browsers by adding a listener on matchMedia('print'), so you could shim it by writing something like the following for those browsers
window.matchMedia('print').addListener(mql => {
if (!mql.matches) {
window.dispatchEvent(newEvent('afterprint'));
}
});
This should work in e.g. Google Chrome
Post a Comment for "Javascript Windows.print() Callback - Determining When A Print Job Completes"