Having an issue with this fragment of code:
const afterPrint = () => {
this.location.back();
window.removeEventListener('afterprint', afterPrint);
};
window.addEventListener('afterprint', afterPrint);
window.print();
I'm trying to redirect the user back in history after they close the print dialog (either by printing or canceling).
In Chrome, everything works fine as expected. However, in Firefox 89, the afterprint
event gets fired when the page is sent to the printer, even if the print dialog is still open.
https://i.stack.imgur.com/INYYt.png
Since the print dialog is still open, the this.location.back()
function is blocked and doesn't work.
I tried it with Firefox 83 before and it worked correctly. But after updating to version 89, I noticed that it no longer functions as intended.
Are there any workarounds for this issue?