In the application I work on, we have several different places a user can print from. In all these cases we are using the same workflow of opening a new window(or tab), writing whatever we need to print to the document of the new window, and then we call
$(w.document).ready(function () {
w.focus();
w.print();
w.close();
});
The issue I'm seeing is that in Chrome, if I close the tab or window that is opened for the print preview instead of clicking the cancel button, Chrome is still blocking the javascript on my parent window.
It is similar to the issue described here:
Google Chrome blocks ajax requests when print preview is opened on child window
We are experiencing this issue as well, but I believe this is a result of how we are implementing printing in a new window and the way Chrome's print preview works. In IE and Firefox, the print window displays the modal dialog, and you are not able to do anything in the parent window until the print window is closed. Similarly chrome is blocking use of the parent window until the print preview is cancelled. However I would expect closing that tab or window to work the same as cancelling the print.
Has anyone else had this issue or know of a good solution?
Thank you!
I can confirm that I have the same bug on Windows 7 using Chrome Version 35 but I share my partial solution who is open a new tab on Chrome and showing a dialog.
For other browser when the user click on cancel automatically close the new print window.
OK here is what worked for me! I have a button on my left Nav. If you click it it will open a window and that window will load a document. After loading the document I want print the document then close the popup window immediately.
Why does did it work?
Well, after printing you set the onfocus event to close the window. The print popup will load so quickly that the onfocus event will not get a chance to trigger until you 1)print 2) cancel the print. Once you regain focus to the window, the window will be closing!
I hope that will work for you
It looks like the problem had been resolved with the latest Chrome update... I'm running the Chrome Version 36.0.1964.4 dev-m.
I was limited too warning the user from closing print preview window by doing the following:
Now the warning is no longer coming up after the Chrome update.
Run this code It will open google print service popup.
Try it on console where x is integer .
Thanks
If the setTimeout function does not work for you either, then do the following:
For those of you who are popping up a new window to print from, and then automatically closing it after the user clicks "Print" or "Cancel" on the Chrome print preview, I used the following (thanks to the help from PaulVB's answer):
I am debating if it would be a good idea to also filter by the version of Chrome...