Printing part of a page

G

Guest

This is probably a real n00b question, but I can't find an answer on
the www and my javascript book doesn't have anything about it.

How do you print part of an html page using the javascript print()
function? Is it possible to put the printable area inside a
<div></div> block and print it, or can you use a hidden style then
print it?

Is there a site on the www which has some information?
 
K

kaeli

This is probably a real n00b question, but I can't find an answer on
the www and my javascript book doesn't have anything about it.

How do you print part of an html page using the javascript print()
function? Is it possible to put the printable area inside a
<div></div> block and print it, or can you use a hidden style then
print it?


I haven't found a way with normal javascript (as opposed to MSIE HTA
JScript/WSH/ActiveX type deals), but if you do, please let me know, too. I've
been looking for a way to do this as well.

Okay, I found a way, but it was a PITA with changing print styles and I
decided it was too much of a boar to bother with. ;)

CSS does support only printing certain things on a page, if that works for
your situation.

--
 
M

Martin Honnen

This is probably a real n00b question, but I can't find an answer on
the www and my javascript book doesn't have anything about it.

How do you print part of an html page using the javascript print()
function? Is it possible to put the printable area inside a
<div></div> block and print it, or can you use a hidden style then
print it?

You can design a CSS stylesheet that suggests how to print the page then
if you call window.print() the browser prints the page following the CSS
rules in the print stylesheet e.g.
<link rel="stylesheet"
media="print"
type="text/css"
href="print.css">
then in the print.css you could for instance have
div#navigationBar { display: none; }
to avoid having the navigation bar (in the <div id="navigationBar">)
printed.

IE also supports event handlers onbeforeprint/onafterprint so there you
could dynamically toggle the display of certain elements in the page.
 
G

Guest

I'm going to try the suggestion below. It is possible to print the
contents of a frame - you can put all of the navigation stuff into a
separate frame and print using something like this:

<input type="button" value="Print"
onClick="parent.right.print();">

I have another page that doesn't use frames and it would be a big pain
to convert it to frames - hence the question.
 

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

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top