Created
August 20, 2013 02:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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