473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

javascript print() not working in new window

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
2 2852
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcus Bjorke | last post by:
I use a print link that causes a problem with Opera 7. The link looks like this <a href="javascript:parent.frames.mainFrame.print()">Print this page</a> I also used <a...
2
by: Bad_Kid | last post by:
Is it possible to print a page that has no "title" and "page number" on the top and no "link adress" and "date" on the bottom (to print just a page just as it is...)? (how, thanks!)
3
by: Ini | last post by:
Hi, Is it possible in Access97 to display in a msgbox the name of the directory I'm working in at that moment? It's like the pwd-command in UNIX-shells. pwd = print working directory ...
0
by: Julieb215 | last post by:
I have an asp.net page that needs to spawn off a popup - printer friendly page. To do that when the user clicks the printer button I fire off the following code: Dim jj As String jj = "<script...
3
by: Bad_Kid | last post by:
(maybe it is not for this group, but...) Is it possible to print a page that has no "title" and "page number" on the top and no "link adress" and "date" on the bottom (to print just a page just...
2
by: tshad | last post by:
I have an ASP.net page where I am trying print the page directly from a printer. The only way I can figure out how to do this is in Javascript with PrintDomTree. The problem is that I don't get...
6
by: redridinghood | last post by:
Cant understand why my javascript is working in ie6 but not in mozilla. The javascript that i hav written for validationg my form is below - <script language="JavaScript"...
0
by: chpadmamca | last post by:
Hi , I am working on JSF application .I need to open print popup window when i click on my JSF command link.How can i achieve this with javascript. Any help would be greatly appreciated as this...
5
by: shawrie | last post by:
Hi can anyone help? Im using VB .NET to automate the faxing of our html pages. The problem is that when i call the submit a print dialog window appears . Is there anyway to supress this? Thanks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.