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):
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
var showPopup = false;
window.onbeforeunload = function () {
if (showPopup) {
return 'You must use the Cancel button to close the Print Preview window.\n';
} else {
showPopup = true;
}
}
window.print();
window.close();
} else {
window.print();
window.close();
}
I am debating if it would be a good idea to also filter by the version of Chrome...