I have a print page that opens in a new tab or window. The resulting page opens a print dialog. After the user makes a selection on the print dialog, the page then closes the tab/window.
window.print();
window.close();
This used to work great in the major browsers, but one of the latest versions of Chrome breaks this (i.e. 14.0.835.202).
I receive the following message from what I guess is the chrome print plugin: "Print preview failed".
Does anyone have a solution to close the Chrome tab/window after printing?
Tested today works for IE, FF, Chrome (including preview fix for chrome)
Similar issue, I had.
FYI FOR ALL AS OF VER 17+ I was using the jquery plugin, printElement and had found a way to edit it so I could close the window, even in chrome ... then they updated to this new print thing! I have a solution yet again.
Now we have this event: WindowEventHandlers.onafterprint (https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onafterprint).
With this event you can do the following:
add this script to your popup print window
contents of print_window_close.js is
basically seTimeout is called only when the document is focused which happens only when the overlay print dialog is closed. hence this works exactly the same way you wanted.
I just managed to come up with a solution that fits me. I started out with the reply from Peru but didn't want to use jQuery in this solution.
For some reason Chrome dont start the timeout timer until the print dialog is closed.
For me i couldn't find a solution so i created one.
What i did is creating an invisible textbox and focus on it by using setInterval every 50ms after the window.print() is called. Also i bound the onfocus event to the textbox and when it get fired i close the window. This is tested on Chrome, Firefox and Internet Explorer.