By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

javascript print() not working in new window

P: n/a
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?
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


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


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

Richard.
Jul 23 '05 #2

P: n/a
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!
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.