Closing a window and printing the contents of a window without Javascript?

D

David Broughton

Hi - I am a very occasional Front Page 2002 user.

I am trying to add a page to my JavaScript-free website that will have a
table of information (no problem there) and two buttons - one that says
close and will close the window, and one that says print and will print out
the contents of the window. The page is opened in a new window using the
"_blank" target frame hyperlink option.

A search of this newsgroup and other sources found many examples that use
JavaScript to close a window - i.e.:
<input type="button" value="Close Order Form" onclick="window.opener = self;
window.close()"&gt; name="Close">, but this causes IE6 to complain about
active content and stops the button from working unless the user
specifically overrides the warning message. That is a pretty ugly solution.

Is there a solution that doesn't rely on Javascript?

How do I enable a print button ?

Thanks for any help -

Dave Broughton
 
J

Jim Buyens

Sorry, but IE is going to "complain" about anything that tries to close a
window. This is a security measure that keeps rogue sites from closing "real"
windows and opening "conterfeit" windows in their place.

As to printing, try <input type="button" value="Print"
onclick="window.print()">

However, in both cases you're duplicating functions that appear in the
browser's toolbar anyway. Are you sure you need this?

Jim Buyens
Microsoft MVP
http://www.interlacken.com
Author of:
*-----------------------------­-----------------------
|\----------------------------­-----------------------
|| Microsoft Windows SharePoint Services Inside Out
|| Microsoft Office FrontPage 2003 Inside Out
||----------------------------­-----------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/----------------------------­-----------------------
*-----------------------------­-----------------------
 
J

Jon Spivey

Hi David,

No to both - closing and printing a window can only be done with javascript.
This code
<input type="button" value="Close Order Form" onclick="window.opener = self;
window.close()"&gt; name="Close">
should be
<input type="button" value="Close Order Form" onclick="window.opener = self;
window.close();">
However this code is only needed if you want to close a window that you
didn't open yourself - it's one of those cute tricks that isn't really
useful in the real world. To close a window all you need is
<input type="button" value="Close Order Form" onclick="window.close();">
 
K

Kevin Spencer

Hi David,

Closing a window is a process. Process means programming. HTML is not
process; it is simply content. As soon as you talk about DOING something,
you're talking about process. The same, of course, goes for Printing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
A

Andrew Murray

It only complains about active content unless it is on a web server. if you
are testing the scripts on your local machine, you'll always get that
message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top