473,834 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<body onload="window. print(); window.close(); ">

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"

Does anyone have an explanation as to why?

Thank you in advance,

Stephen

Dec 23 '05 #1
22 130521
st*****@ploughb ooksales.com.au wrote:
<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"

Does anyone have an explanation as to why?


You are trying to close the window that displays the document you want to
print.
PointedEars
Dec 23 '05 #2
st*****@ploughb ooksales.com.au wrote:
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"


My testing in Firefox 1.5 seems to indicate that window.print is
asynchronous; that is, the script does not wait for the dialog box to
be closed before continuing. For example, if you change your onload
handler to the following:

<body onload="window. print(); alert('foo');">

....then Firefox will show the "foo" alert first, and then the Print
dialog.

Unfortunately, it seems that window.print has never been part of any
formal specification, so it's meaningless to ask whether being
synchronous or asynchronous is the "correct" behavior. However, it's
pretty obvious that no matter what, it shouldn't be able to crash the
browser.

-- David

Dec 23 '05 #3
Thanks for the explanations.

So is there a way of closing the document after it has been printed, or
can I only leave it there is an artifact for the customer to close.

Stephen

Dec 24 '05 #4
st*****@ploughb ooksales.com.au wrote:
Thanks for the explanations.

So is there a way of closing the document after it has been printed, or
can I only leave it there is an artifact for the customer to close.


There is no need to create a 'print friendly' version in a separate
window at all, or even use JavaScript - use a print-medium style sheet:

<URL: http://www.alistapart.com/stories/goingtoprint/ >

--
Rob
Dec 24 '05 #5
On 2005-12-23, st*****@ploughb ooksales.com.au <st*****@plough booksales.com.a u> wrote:
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"

Does anyone have an explanation as to why?


if window.print() is executes asynchronously the page
is unloaded before it can be printed...

sounds like a bug in Netscape to me.

FWIW it works fine in Mozilla

Bye.
Jasen
Dec 24 '05 #6
VK

st*****@ploughb ooksales.com.au wrote:
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"

Does anyone have an explanation as to why?


window.print() is not a *process*, it is simply a request to display
print dialog (same as choosing File > Print). Therefore ideas of sync /
async are not applicable here.

IE has full set of event listeners to fine tune the printing *process*:
onlayoutcomplet e
onberoreprint
onafterprint

Unfortunately these listeners still have to be implemented by the
wannabes. Untill then it is better to leave the content window open.

Dec 24 '05 #7
VK wrote:
st*****@ploughb ooksales.com.au wrote:
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"

Does anyone have an explanation as to why?

window.print() is not a *process*, it is simply a request to display
print dialog (same as choosing File > Print). Therefore ideas of sync /
async are not applicable here.


Maybe that is your opinion based on one browser. The Mozilla DOM
reference says that window.print():

"Prints the current document."

<URL:http://developer.mozil la.org/en/docs/DOM:window.prin t>
The Netscape Devedge JS Reference says:

"Prints the contents of the window."

<URL:http://devedge-temp.mozilla.or g/library/manuals/2000/javascript/1.3/reference/window.html#120 3138>
I think the important thing here is that window.print() is DOM 0[1],
and therefore how it works is implementation dependent. You can't
state categorically what it is or does because there is no common
specification that states what it should do, though you might be able
to state what it does in regard to a particular browser.

There are some browsers that don't implement it at all. The best
solution for the OP is to offer a print medium style sheet. If the
browser supports it, it will be used. If not, the window will be
printed as-is.

The use of script in this case is simply not required, there are
already a number of ways to print the page, why add another
(unreliable) method?
1. DOM 0 'refers to a mix (not formally specified) of HTML document
functionalities offered by Netscape Navigator version 3.0 and
Microsoft Internet Explorer version 3.0. In some cases, attributes
or methods have been included for reasons of backward compatibility
with "DOM Level 0".'

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/glossary.html#d t-DOM-Level-0>

[...]
--
Rob
Dec 25 '05 #8
VK

RobG wrote:
VK wrote:
window.print() is not a *process*, it is simply a request to display
print dialog (same as choosing File > Print). Therefore ideas of sync /
async are not applicable here.


Maybe that is your opinion based on one browser. The Mozilla DOM
reference says that window.print():

"Prints the current document."

<URL:http://developer.mozil la.org/en/docs/DOM:window.prin t>
The Netscape Devedge JS Reference says:

"Prints the contents of the window."

<URL:http://devedge-temp.mozilla.or g/library/manuals/2000/javascript/1.3/reference/window.html#120 3138>


I'm ususally trying to avoid rude comments, but both quoted definitions
are bs^2 - which brings us back to the discussion of benefits and
drawbacks of wiki'ed manuals.

windowObject.pr int() is nothing but GUI call and it never was anything
else, and it never be anything else for security reasons (print 10,000
copies of current page - would you like it?)

windowObject.pr int() simply displays the dialog where user can press
"Yes" - and it starts the printing *process*, or user can press
"Cancel" - and it will be the end of the story (the *process* will
never start).

In the case of:
windowObject.pr int();
windowObject.cl ose();

script execution halts after the first statement as for any modal
dialog. After the modal dialog is closed nothing prevents the script to
execute the second statement, no matter if user pressed Yes or Cancel.

The only reason it works (sometimes!) in IE - is that IE as usual makes
extra step to try to understand user's intentions. In the particular it
guesses that if windowObject is chosen to be printed, then it shouldn't
be destroyed at least until print job is prepared and sent to the
printer. It is a very helpful formal reasonning - but IE does it on its
own behalf and not obligated by any standards.

Dec 25 '05 #9
VK wrote:
RobG wrote:
VK wrote:
window.print () is not a *process*, it is simply a request to display
print dialog (same as choosing File > Print). Therefore ideas of sync /
async are not applicable here.
Maybe that is your opinion based on one browser. The Mozilla DOM
reference says that window.print():

"Prints the current document."

<URL:http://developer.mozil la.org/en/docs/DOM:window.prin t>
The Netscape Devedge JS Reference says:

"Prints the contents of the window."

<URL:http://devedge-temp.mozilla.or g/library/manuals/2000/javascript/1.3/reference/window.html#120 3138>

I'm ususally trying to avoid rude comments, but both quoted definitions
are bs^2


? They are descriptions of what window.print does from a certain point
of view. My intention was to show that different browsers have
different ideas of what it does and that it is not controlled by any
standard.

which brings us back to the discussion of benefits and
drawbacks of wiki'ed manuals.
That is irrelevant. Devedge isn't a wiki, the Mozilla wiki
documentation does not allow anonymous entries, though there is no
restriction on who may open an account so it's scant control but it
does seem to have worked OK so far.

If you don't like the Mozilla entry, update it.

windowObject.pr int() is nothing but GUI call and it never was anything
else, and it never be anything else for security reasons (print 10,000
copies of current page - would you like it?
If someone wanted to create a browser that did that, then so be it but
it would be a rather nasty feature. Word and Excel both have buttons
on their toolbars that send documents directly to the printer without
displaying a dialog. Both support scripting that allows a script to
submit documents directly to the printer too. Clearly somebody thinks
it's a good idea in some cases.

But in any case, it's irrelevant. This discussion isn't about why
window.print works as it does, it's that you consider it to have only
one defined process. My point was that there isn't one (though
Netscape's crashing is a rather disappointing why of handling the
situation :-) ).

[...]
The only reason it works (sometimes!) in IE - is that IE as usual makes
extra step to try to understand user's intentions.
Hardly. IE appears to do exactly what Firefox does - it waits for the
outcome of the print dialog before proceeding with the script which
would appear to be the logical thing to do.

[...]
- but IE does it on its
own behalf and not obligated by any standards.


Exactly.

It would be interesting to see what happens if the onbeforeprint event
is 'window.close() ';

--
Rob
Dec 26 '05 #10

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

Similar topics

2
1229
by: mark | last post by:
im printing pages using RegisterStartupScript("startupScript", "<script language='javascript'>window.print();</script>") in code behind how do i do this to only print the main frame ? thanks mark
2
1611
by: Taoge | last post by:
Hi, all When we click or select Print in IE, a print windows pop-up, is there anyway to capture this message and get the information of the print window (i.e. pages ,paper,defualt printer,...) and i can control the printing job continue or cancel it. thanks a lot
0
1006
by: Tank | last post by:
Hi How to send report directly to printer from Acrobat Reader without going thru the Print window when clicking printer icon at AR? Please advice. Thanks.
1
8652
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...
2
5131
by: colinzhu | last post by:
I want to have the print dialog shown automatically after the the page is loaded, but when I try to call window.print() BEFORE the iframe, the print dialog is not shown at all. Anyone can help? Here is my code: <html> <head> <title>Auto print the page</title> </head>
3
2189
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
All, I created window form application, has one Print button on the form, when hit the button, then print this form. I know vb6 use me.printform, but for vb.Net I don't know how, anyone has clue? Thanks, martin
0
9644
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
10793
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10509
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...
1
10547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9331
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
7757
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
5626
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...
0
5793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.