crabbly / Print.js

A tiny javascript library to help printing from the web.
MIT License
4.29k stars 672 forks source link

firefox onPrintDialogClose and redirect not working #580

Open ilongoat opened 3 years ago

ilongoat commented 3 years ago

hi there wonderful job - I really appreciate your work.

Just encountered a small bug

on FIREFOX ( latest version mc & windows )

printJS({printable:'dummy.pdf', type:'pdf', onPrintDialogClose: () => window.location='whatever.html'});

not working

if I click in the Adressbar and afterwards in the website -> trigger is fired and reload is done

so somehow firefox loses the focus on the current window

Any help very appreciatet

My workaround this time SetTimeout function .. fires after 11 seconds ( enough time for the users to print the socument )

qdelcourte commented 3 years ago

Hi,

I think Firefox main document doesn't get the focus back after iframe is removed.

Iframe is focused at the beginning in line 55 and apparently it's not necessary for all the browsers because I commented this line and now it's working great on Firefox 91.0. In all cases, Chrome works with or without.

https://github.com/crabbly/Print.js/blob/6502c73c7e1ba87346fe4913fa5de6220936095b/src/js/print.js#L53-L79

So the question is: Why the focus in line 55 is needed ? Is this needed for all browsers ? (I also checked Chrome, Chromium, Edge on Linux)

daphnesmit commented 2 years ago

I removed iframeElement.focus() in my typescript port of this library in https://github.com/daphnesmit/prntr