Reputation: 147
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 accomplishes this. Note - I have access to the computers if I need to install something.
Background: I have implemented a web POS solution that runs on Firefox (v44-46). For some orders, I need to print 2 receipts on an Epson TM-T88V printer.
Problem: If the second windows.print()
method executes while the first receipt is still printing, Firefox prompts "Some printing functionality is not available".
Possible Solution: I can increase the delay between print calls. However, this isn't very robust since some orders can be quite lengthy, whereas others are not. This solution might not work for some cases, and would simply slow down others.
Is there a better way to go about doing this?
Upvotes: 0
Views: 2164
Reputation: 66384
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(new Event('afterprint'));
}
});
This should work in e.g. Google Chrome
Upvotes: 1