?
Solved

Print only part of web page

Posted on 2004-11-30
1
Medium Priority
?
2,332 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:jayme9
1 Comment
 
LVL 5

Accepted Solution

by:
prohacx earned 1000 total points
ID: 12705294
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question