Reputation: 385
I have a parent page calling the child popup page to show the print page. After redirecting to print page If I close the the child page I can do other activities in parent page, but when I minimize my Child page (print page) and try some activity it is not responding, after closing the Child page what ever I did it is recreating.
Code:
var chartDiv = document.getElementById('innerchartdiv');
var outerContainerDiv = document.getElementById('outerContainer');
var divToPrint = chartDiv.innerHTML;
setTimeout(function(){
var popupWin = window.open('', '_blank', 'width=800px,height=800px');
popupWin.document.open();
popupWin.document.write('<html><body align="center" style="margin:0% 17%;font-size:9px;">' + chart+'</html>');
popupWin.document.close();
popupWin.focus();
popupWin.print();
popupWin.close();
Upvotes: 3
Views: 2238
Reputation: 572
Unfortunately, if you call print on the popup, it is the same as an alert box, it blocks the thread! I've had that problem before, and the answer is that the print dialogue will always block the JS thread.
This is the reason, many websites open a generated PDF in a new tab, rather than using the print dialogue. I know it's not the answer you want, but that's why people use custom alert boxes too. Blocking the execution of JS for the user interface ruins the user experience, and stops all animation and events firing, until you have clicked.
You can't control the popup from JS, it literally has to be a hyperlink. However there is a way of doing this without the server. client side PDF generation tools and 'Blob URLs' work in modern browsers, so you can do client side PDF generation too. Try jsPDF, I haven't used that one but it might do the trick.
ALSO:
Cross browser print css and sizing is not very uniform, so if you want to control the layout, again the PDF generation is by far the easiest option to ensure the page is printed in the intended way. I don't really love the PDF format, but that is the reason it's so popular.
Upvotes: 3