Redirect via onafterprint working in Chromium but not Firefox
I am trying to serve a print view and redirect the user to the page they came from right after printing (or cancelling). This works fine in Chromium with the following bi… (read more)
I am trying to serve a print view and redirect the user to the page they came from right after printing (or cancelling). This works fine in Chromium with the following bit of JavaScript code:
function printPageAndRedirectTo(redirectUrl) { window.addEventListener("afterprint", function () { window.location.href = redirectUrl; }); window.print();
In Firefox, however, nothing happens at all. Debugging shows that the callback is called, but the href field remains unchanged.
This is mysterious to me. Any ideas what the reason might be?
Firefox version is 84.0.2, Chromium 87.0.4280.88 (both from the Arch Linux repositories).
Edit:
Here's a fiddle to illustrate. Redirect to Wikipedia works in Chromium but not in Firefox: https://jsfiddle.net/xnazLb6p/1/
Edit 2:
Another one to show that the problem here is redirecting from the event listener, not redirecting itself: https://jsfiddle.net/xnazLb6p/2/