Connecting Tech Pros Worldwide Forums | Help | Site Map

Printing part of a page

robert.spam.me.senseless@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
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?


kaeli
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Printing part of a page


In article <1113381063.225212.164710@g14g2000cwa.googlegroups .com>,
robert.spam.me.senseless@gmail.com enlightened us with...[color=blue]
> 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?
>[/color]


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.

--
--
~kaeli~
Who is General Failure and why is he reading my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Martin Honnen
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Printing part of a page




robert.spam.me.senseless@gmail.com wrote:
[color=blue]
> 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?[/color]

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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
robert.spam.me.senseless@gmail.com
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Printing part of a page


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.

robert.spam.me.senseless@gmail.com
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Printing part of a page


Forget what I just put above - the stylesheet suggestion works a treat.

Thanks.

Closed Thread


Similar JavaScript / Ajax / DHTML bytes