Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Redirect via onafterprint working in Chromium but not Firefox

  • 1 reply
  • 1 has this problem
  • Last reply by jscher2000

more options

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;

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).


Here's a fiddle to illustrate. Redirect to Wikipedia works in Chromium but not in Firefox:

Edit 2:

Another one to show that the problem here is redirecting from the event listener, not redirecting itself:

All Replies (1)

more options

Hmm, I added

console.log('Calling location.href...');

as the first line of your event handler function. The text prints to the console right away as the Print dialog appears, rather than once printing is completed. I suspect that having the Print dialog still up locks the page and prevents the navigation, but that's just a guess.

This seems to be the relevant bug, but the comments are confusing about whether it was fixed in Firefox 51 or not:


Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.