Question

I've application to open popup window to print page.

function printHTML(urlPath) {
    var printPopUp = window.open(urlPath,null,"height=600,width=777,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
    printPopUp.print();
}

This script is working fine in IE, but in firefox/chrome. print() function is overlapping window.open, as a result the print dialog is showing first while screen is still loading. I need to close print dialog in order to render the page properly then print manually.

Please advise.

Was it helpful?

Solution

As indicated in your comment, the urls to print are on the same domain. You cannot access the content of the other windows so you will have to set up some code on the popped up window that will call the opener to tell it it has opened.

popup.html

<script>
function onLoad() {
  if(window.opener && window.opener.popupLoaded) {
    window.opener.popupLoaded();  
  }
}
</script>
<html onload="onLoad();">

main.html

function popupLoaded() {
  popup.print();
}

OTHER TIPS

Run print after the page is loaded, e.g.

printPopUp.onload = function() { printPopUp.print() }

(not tested)

I suggest calling window.print() in the page being loaded into the pop-up rather than in the opener.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top