Monday, May 20, 2024
74
rated 0 times [  77] [ 3]  / answers: 1 / hits: 120510  / 10 Years ago, mon, april 14, 2014, 12:00:00

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!


More From » google-chrome

 Answers
63

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:



if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){   // Chrome Browser Detected?
window.PPClose = false; // Clear Close Flag
window.onbeforeunload = function(){ // Before Window Close Event
if(window.PPClose === false){ // Close not OK?
return 'Leaving this page will block the parent window!nPlease select Stay on this Page option and use thenCancel button instead to close the Print Preview Window.n';
}
}
window.print(); // Print preview
window.PPClose = true; // Set Close Flag to OK.
}


Now the warning is no longer coming up after the Chrome update.


[#71463] Saturday, April 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;