Connecting Tech Pros Worldwide Forums | Help | Site Map

javascript print() not working in new window

Asad
Guest
 
Posts: n/a
#1: Jul 23 '05
I have a main window that creates a new window called printWin (which
contains the printable format of the page). From the main window I
embed a javascript in the printWin window that calls the
"window.print()" function. So it looks like this:

printWin.document.write ("<FORM>");
printWin.document.write ("<INPUT TYPE=\"BUTTON\" NAME=\"btnPrint\"
VALUE=\"Print\" ONCLICK=\"javascript:window.print()\">");
printWin.document.write ("</FORM>");

But this has absolutely no effect when clicked. I tried printing out
the window name, but it was blank. I dont know why that is. Maybe its
coz I'm dynamically creating the new window? BTW, if its of any
relevance, I copy the body of the main window into printWin and then
make some changes to it (basicallly convert all text boxes into text).

Any ideas?

Richard Cornford
Guest
 
Posts: n/a
#2: Jul 23 '05

re: javascript print() not working in new window


Asad wrote:
<snip>[color=blue]
> printWin.document.write ("<FORM>");
> printWin.document.write ("<INPUT TYPE=\"BUTTON\" NAME=\"btnPrint\"
> VALUE=\"Print\" ONCLICK=\"javascript:window.print()\">");
> printWin.document.write ("</FORM>");[/color]
<snip>[color=blue]
> Any ideas?[/color]

Once you have written to the document in the new window, do you close
the document using - printWin.document.close() - ?

Richard.


Asad Khan
Guest
 
Posts: n/a
#3: Jul 23 '05

re: javascript print() not working in new window


Ok something better but even more wierd ...

The javascript is in my main window. In there I create the new window as
follows:


printWin=open('','printWindow','resizable=no,width =690,height=600,menuba
r=yes,status=no,scrollbars=yes');

This window's name is clearly printWindow. Anyways, further down I have
this code:

var c = printWin.document.createElement("center");
var foo = printWin.document.createElement("form");
var btnPrint = printWin.document.createElement( 'button' );
btnPrint.setAttribute("name", "p");
btnPrint.setAttribute("value", "Print");
btnPrint.setAttribute("onclick", "executePrint()");
btnPrint.onclick=function(){printWin.print();};
var btnClose = printWin.document.createElement( 'button' );
btnClose.setAttribute("name", "c");
btnClose.setAttribute("value", "Close");
btnClose.onclick=function(){printWin.close();};
foo.appendChild( btnPrint );
foo.appendChild( btnClose );
c.appendChild( foo );
printWin.document.body.insertBefore
(c,printWin.document.body.firstChild);

This creates two buttons on top of my new (print) window. The wierd
thing is that close button works fine! It closes the print window that
has been created (popped up). However, the print button has no effect
whatsoever!

I tried window.print() but that causes the original main window to get
printed. And I also tried printWindow.print() for which I get this dumb
error saying printWindow is undefined.

Also, since these buttons are dynamically generated they dont appear in
the view source of my pop up, but I doubt thats got anything to do with
it.

So how do I get the print screen to print properly using this button?






*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Closed Thread