Skip to content

Instantly share code, notes, and snippets.

@esfand-r
Created August 20, 2013 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esfand-r/6276626 to your computer and use it in GitHub Desktop.
Save esfand-r/6276626 to your computer and use it in GitHub Desktop.
With the latest version of chrome, when the popup blocked, the chrome crashes while trying to print. This is some weird workaround that worked for me! Useful also when trying to detect popup blocker in Chrome.
function popupPrint(html) {
var width = 1100;
var height = 700;
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
var printWindow = window.open("", "PrintWindow", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);
setTimeout(function () {
if (!printWindow || printWindow.closed || printWindow.closed == "undefined" || printWindow == "undefined" || parseInt(printWindow.innerWidth) == 0 || printWindow.document.documentElement.clientWidth != 1100 || printWindow.document.documentElement.clientHeight != 700) {
printWindow && printWindow.close();
$.alert("Popup Blocked", {icon: "EXCLAMATION", title: "Popup Blocked!" });
} else {
printWindow.document.writeln(html);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
}, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment