Print only part of web page

Hello,

I'm trying to print only part of a web page.   For example, I would like to print everything within the <DIV> tag.  I guess I just need help setting up the javascript.  What I don't want to end up doing is creating another duplicate page just to have it be the Print-Friendly one.  THis is the framework I have so far...

'This is the link that prints the page (actually the section of the page)
<a href="javascript:void(printSpecial())">Print this page</a>

'This is the javascript in the HEAD of my page:
<Script Language="Javascript">
function printSpecial()
var printReadyElem = document.getElementById("printReady");
This is where I need help.  I want to Print all content within the document.getElementById("printReady")
</Script>

'This is my DIV tag
<div id="printReady">All my text and such I want actually printed will go in here.</div>


THank you,
Jayme
jayme9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prohacxCommented:
Hi there Jayme!

There are 2 ways of solving this issue:

1. Remove all unnecessary content from your document using JavaScript
2. Use a nice stylesheet to solve your problem.

I'll explain the second one, since I believe this is the 'best' solution:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> CSS and printers </TITLE>

<style type="text/css">

      @media screen {

            .unprintable {
                  display: block;
            }
            .printable {
                  display: block;
            }

      }

      @media print {

            .unprintable {
                  display: none;
            }
            .printable {
                  display: block;
            }

      }

</style>

</HEAD>

<BODY>

<div class="unprintable">
some things unprinted here
</div>

<div class="unprintable">
some things unprinted here
</div>

<div class="printable">
PRINT THIS
</div>

<div class="unprintable">
some things unprinted here
</div>

<div class="unprintable">
some things unprinted here
</div>


</BODY>
</HTML>


As you can see, you can setup a styelsheet for each medium you use (screen, printer, handheld, ...) and determine what and how to display it on this medium. I use this way to hide buttons on printed forms, because clicking on the paper does not really do anything, does it? ;-)


Good luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.