473,738 Members | 3,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Generate d 2/19/2004 at 14:18</TITLE>
</HEAD>
<BODY bgcolor='#FFFFF F' 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,IMGHE IGHT,WINWIDTH,W INHEIGHT) {
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,lo cation=0,status bar=0,menubar=0 ,resizable=0,wi d
th=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
newWindow.docum ent.write("<HTM L><HEAD><TITLE> Generated "+ dateTime
+"</TITLE></HEAD><BODY bgcolor='#FFFFF F' text='#000000' style='margin:
0em'><DIV ALIGN='center'> <IMG SRC=" +URL+ " width=" +IMGWIDTH+ " height="
+IMGHEIGHT+ "><form><in put type=button value=\"Print Document\"
onclick=\"windo w.print()\"></form></DIV></BODY></HTML>")
newWindow.docum ent.close
}
//-->
</SCRIPT>
Jul 20 '05 #1
3 8355
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*****@micros oft.com> wrote in message
news:q%******** **********@twis ter.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>Generate d 2/19/2004 at 14:18</TITLE>
</HEAD>
<BODY bgcolor='#FFFFF F' 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,IMGHE IGHT,WINWIDTH,W INHEIGHT) {
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,lo cation=0,status bar=0,menubar=0 ,resizable=0,wi d th=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
newWindow.docum ent.write("<HTM L><HEAD><TITLE> Generated "+ dateTime
+"</TITLE></HEAD><BODY bgcolor='#FFFFF F' text='#000000' style='margin:
0em'><DIV ALIGN='center'> <IMG SRC=" +URL+ " width=" +IMGWIDTH+ " height="
+IMGHEIGHT+ "><form><in put type=button value=\"Print Document\"
onclick=\"windo w.print()\"></form></DIV></BODY></HTML>")
newWindow.docum ent.close
}
//-->
</SCRIPT>

Jul 20 '05 #2
"Craig" <so*****@micros oft.com> wrote in message
news:q%******** **********@twis ter.rdc-kc.rr.com...
<snip>
eval("newWindow = window.open('', '"+ id
+"','toolbar=0 ,scrollbars=0,l ocation=0,statu sbar=0,menubar= 0,
resizable=0,wi dth=" +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=ye s,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.docum ent.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*****@litote s.demon.co.uk> wrote in message
news:c1******** ***********@new s.demon.co.uk.. .
"Craig" <so*****@micros oft.com> wrote in message
news:q%******** **********@twis ter.rdc-kc.rr.com...
<snip>
eval("newWindow = window.open('', '"+ id
+"','toolbar=0 ,scrollbars=0,l ocation=0,statu sbar=0,menubar= 0,
resizable=0,wi dth=" +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=ye s,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.docum ent.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
4993
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. forkme.pl calls the process creation script (createme.pl) 5. createme.pl creates my notepad.exe process, but no window shows up on my PC. The result on my web browser is:
2
1600
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, but it's making me crazy. Shouldn't it work in both the interactive window and a script? >>> d = "5-18-05 to 5-31-05" >>> print d
6
1795
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, print-friendly way. The main window is loaded with options, textboxes, buttons, has some graphics etc, nice as an app but not really printable, so clicking "print" icon opens a new window with the page with a nicely formatted, print-friendly...
9
10848
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
130334
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 document and closes it with the following code: <body onload="window.print(); window.close();"> This works correctly (or at least the way I expect it to work under MS Internet Explorer, but it cuases Netscape to "crash"
5
2529
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); I don't get any errors and other writes before and after work fine. myWindowArray is not null and does have elements.
0
1805
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 out which signal it generates. Searching around the subject on the web doesn't seem to pull up anything useful. I tried the "focus" signal, but that doesn't work the way I'd like it to. For example, the following code only prints the message...
1
8646
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 viewer's gui button. I have a Windows XP sp2 Client machine used for development, it has Visual Studio 2005 sp1 and CR XI R2 Developer Version. My webserver is running Windows Server 2003 sp1, IIS 6.0, has CR XI R2 developer. I have a working...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.