473,382 Members | 1,766 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,382 software developers and data experts.

window.print() doesn't work!?

First of all, this one is driving me crazy, so thanks in advance for any
help!!

I've got a javascript function in a parent document that generates an HTML
document on the fly when a button is clicked... that generated popup
contains a button that's supposed to print the contents of the popup window
(self). However, the button won't print (nothing happens on click) from the
newly generated popup to print the contents of the window... the complete
source for the generated page is below, I've tried every combination I can
think of, but absolutely nothing happens when I click the button... I tried
the right-click print from the context menu, and everything comes up... so,
the issue's in code somewhere! argh!

<HTML>
<HEAD>
<TITLE>Generated 2/19/2004 at 14:18</TITLE>
</HEAD>
<BODY bgcolor='#FFFFFF' text='#000000' style='margin: 0em'>
<DIV ALIGN='center'>
<IMG SRC=graphs/ChartPic_000001.jpeg width=600 height=300>
<form>
<input type=button value="Print Document" onclick="window.print()">
</form>
</DIV>
</BODY>
</HTML>
...and just in case someone is interested in the code that generates this
window in the parent page... it's below...

<!-- Begin
function popUp(URL,TITLE,IMGWIDTH,IMGHEIGHT,WINWIDTH,WINHEI GHT) {
day = new Date();
id = day.getTime();
dateTime = day.getMonth()+1 +'/'+ day.getDate() +'/'+ day.getFullYear() +'
at '+ day.getHours() +':'+ day.getMinutes();
eval("newWindow = window.open('','"+ id
+"','toolbar=0,scrollbars=0,location=0,statusbar=0 ,menubar=0,resizable=0,wid
th=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
newWindow.document.write("<HTML><HEAD><TITLE>Gener ated "+ dateTime
+"</TITLE></HEAD><BODY bgcolor='#FFFFFF' text='#000000' style='margin:
0em'><DIV ALIGN='center'><IMG SRC=" +URL+ " width=" +IMGWIDTH+ " height="
+IMGHEIGHT+ "><form><input type=button value=\"Print Document\"
onclick=\"window.print()\"></form></DIV></BODY></HTML>")
newWindow.document.close
}
//-->
</SCRIPT>
Jul 20 '05 #1
3 8332
OK, I did some additional testing, and if i view source, then save that to
an .html and open it with NO changes - the code works...

So, is there something (security?) keeping this function from working from a
popup window? Is it because I've hidden the toolbar, status, etc?

"Craig" <so*****@microsoft.com> wrote in message
news:q%******************@twister.rdc-kc.rr.com...
First of all, this one is driving me crazy, so thanks in advance for any
help!!

I've got a javascript function in a parent document that generates an HTML
document on the fly when a button is clicked... that generated popup
contains a button that's supposed to print the contents of the popup window (self). However, the button won't print (nothing happens on click) from the newly generated popup to print the contents of the window... the complete
source for the generated page is below, I've tried every combination I can
think of, but absolutely nothing happens when I click the button... I tried the right-click print from the context menu, and everything comes up... so, the issue's in code somewhere! argh!

<HTML>
<HEAD>
<TITLE>Generated 2/19/2004 at 14:18</TITLE>
</HEAD>
<BODY bgcolor='#FFFFFF' text='#000000' style='margin: 0em'>
<DIV ALIGN='center'>
<IMG SRC=graphs/ChartPic_000001.jpeg width=600 height=300>
<form>
<input type=button value="Print Document" onclick="window.print()">
</form>
</DIV>
</BODY>
</HTML>
..and just in case someone is interested in the code that generates this
window in the parent page... it's below...

<!-- Begin
function popUp(URL,TITLE,IMGWIDTH,IMGHEIGHT,WINWIDTH,WINHEI GHT) {
day = new Date();
id = day.getTime();
dateTime = day.getMonth()+1 +'/'+ day.getDate() +'/'+ day.getFullYear() +' at '+ day.getHours() +':'+ day.getMinutes();
eval("newWindow = window.open('','"+ id
+"','toolbar=0,scrollbars=0,location=0,statusbar=0 ,menubar=0,resizable=0,wid th=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
newWindow.document.write("<HTML><HEAD><TITLE>Gener ated "+ dateTime
+"</TITLE></HEAD><BODY bgcolor='#FFFFFF' text='#000000' style='margin:
0em'><DIV ALIGN='center'><IMG SRC=" +URL+ " width=" +IMGWIDTH+ " height="
+IMGHEIGHT+ "><form><input type=button value=\"Print Document\"
onclick=\"window.print()\"></form></DIV></BODY></HTML>")
newWindow.document.close
}
//-->
</SCRIPT>

Jul 20 '05 #2
"Craig" <so*****@microsoft.com> wrote in message
news:q%******************@twister.rdc-kc.rr.com...
<snip>
eval("newWindow = window.open('','"+ id
+"','toolbar=0,scrollbars=0,location=0,statusbar= 0,menubar=0,
resizable=0,width=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
This operation does not require the - eval - function. eval is almost
never needed in javascript.

<URL: http://jibbering.com/faq/#FAQ4_40 >

newWindow = window.open('', id,
('scrollbars=yes,resizable=yes,width=" +
WINWIDTH+ ",height=" +
WINHEIGHT));

It is never a good idea to open a window that is not resizable, it makes
no significant difference to the appearance and if not resizable the
onus is on the programmer to open the window the correct size. There are
so many variable (and some unknowable) factors involved in determining
the correct size for a new window that no adequate
cross-browser/configuration code exists for the task. So the only way of
guaranteeing that the user will be able to access the content of a
window is to leave it resizable and preferably enable the scrollbars. If
any one window feature is specified then any unspecified features will
be set to off.

<snip> newWindow.document.close

^^^
The close function of the document should be called to close the
document. an expression that does no more that refer to it will not
achieve that.

<snip>

Richard.
Jul 20 '05 #3
Yes, Yes, and Yes... I agree with your resizable, I'm going to change that.

More importantly, you're right about the close... since it wasn't called the
document was hanging open and IE won't open the print dialog from js while
the page is still loading... once I got that close on there correctly, it
worked exactly as expected.

Thanks so much!

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:c1*******************@news.demon.co.uk...
"Craig" <so*****@microsoft.com> wrote in message
news:q%******************@twister.rdc-kc.rr.com...
<snip>
eval("newWindow = window.open('','"+ id
+"','toolbar=0,scrollbars=0,location=0,statusbar= 0,menubar=0,
resizable=0,width=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");


This operation does not require the - eval - function. eval is almost
never needed in javascript.

<URL: http://jibbering.com/faq/#FAQ4_40 >

newWindow = window.open('', id,
('scrollbars=yes,resizable=yes,width=" +
WINWIDTH+ ",height=" +
WINHEIGHT));

It is never a good idea to open a window that is not resizable, it makes
no significant difference to the appearance and if not resizable the
onus is on the programmer to open the window the correct size. There are
so many variable (and some unknowable) factors involved in determining
the correct size for a new window that no adequate
cross-browser/configuration code exists for the task. So the only way of
guaranteeing that the user will be able to access the content of a
window is to leave it resizable and preferably enable the scrollbars. If
any one window feature is specified then any unspecified features will
be set to off.

<snip>
newWindow.document.close

^^^
The close function of the document should be called to close the
document. an expression that does no more that refer to it will not
achieve that.

<snip>

Richard.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
2
by: Bell, Kevin | last post by:
The following works in the interactive window of PythonWin, but fails in a script. TypeError: Objects of type 'slice' can not be converted to a COM VARIANT I just need to parse out these dates,...
6
by: bwucke | last post by:
Short: One window writes to <input>, the other reads the same <input>. Is it a race condition or are the reads/writes atomic? Long: My app has an option to print results in a nicely formatted,...
9
by: David A. Beck | last post by:
When I do a debug.print("blabla") in VB (VS2005) it doesn't show up in the output window, what gives?
22
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the...
5
by: VisionSet | last post by:
Anyone know why this line fails to print anything? document.write(window.top.myWindowArray.name); For that matter, neither does this: document.write('>>' + window.top.myWindowArray.name); ...
0
by: Peter TB Brett | last post by:
Hi folks, I'm currently trying to work out how to detect when a PyGTK window receives the focus from the window manager -- I assume that it must receive some kind of X event, but I can't work...
1
by: Kbalz | last post by:
Having a really hard time finding solid examples on deploying a CR .NET applcation on my intranet. I'll explain what I've done so far, and toward the bottom is where I can't print using the report...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.