Javascript popup popup page blocking parent actions

I have a parent page that triggers a popup to display the print page. After being redirected to the print page. If I close the child page, I can do other actions on the parent page, but when I minimize my Child page (print page) and try any activity, it doesn't respond, after closing the Child page, which ever did he recreate.

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();

      

+3


source to share


1 answer


Unfortunately, if you call print in the popup, this is the same as the alert box, it will block the thread! I had this problem before and the answer is that the print dialog will always block the JS stream.

For this reason, many websites open the generated PDF document in a new tab rather than using the print dialog. I know this is not the answer you want, but why people also use custom alerts. Blocking JS execution for the UI disrupts the user experience and stops all animations and events until you click.

Alternative suggestion:



You cannot control the popup from JS, it literally has to be a hyperlink. However, there is a way to do this without a server. client-side PDF creation tools and "Blob URLs" work in modern browsers, so you can also create client-side PDFs. Try jsPDF , I haven't used it, but it might do the trick.

and

Cross-browser print css and size are not very uniform, so if you want to control the layout, again, PDF generation is the easiest option to ensure that the page is printed as intended. I really don't like the PDF format, but for this reason it is so popular.

+2


source







All Articles