views:

550

answers:

3

Hi, 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 print dialog is showing first while screen is still loading. I need to close print dialog in order to render page properly then print manually.

Please advise.

A: 

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

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

(not tested)

Nickolay
in Chrome at least that will not work.
Kinlan
it doesn't work in FF3+Chrome
Adelave
A: 

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

Tim Down
can't because this is global script, its shared on all pages. If i'm doing that way, i need to duplicate code on all pages.
Adelave
A: 

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 onoad="onLoad();">

main.html

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