When in our webapp a Chrome subwindow is launched, either by window.open()
or by user clicking a link with target="_blank"
, then in that subwindow, body onload="window.print()"
to auto-launch the print dialog and print preview, then user CLOSES the print/subwindow instead of clicking cancel, the parent window gets completely hosed. Specifically:
If you click cancel on the subwindow (where the print-preview is launched via window.print()
) everything is fine. But if user closes the window, all the craziness happens.
This is a known bug in Chrome:
Does anyone know of a workaround for this?
Instead of using window.print()
, just bring your content to new window and then call print functionality as given below, to print the content.
following is a function call where we passed element's inner html through it's id to new window.
PrintContent(document.getElementById('div-content-id').innerHTML);
function PrintContent(printableContent) {
var printWindow = window.open("", "Print_Content", 'scrollbars=1,width=900,height=900top=' + (screen.height - 700) / 2 + ',left=' + (screen.width - 700) / 2);
printWindow.document.write(printableContent);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
return false;
}
I was also facing same problem, it works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With