tags:

views:

36

answers:

3

Hi friends

I have an html page i want to print a portion of this html page, I know a javascript function to print a page, onClick="javascript:window.print(); return false;

but how can i print a portion of a page.

Any one have an idea, please share it to me

Thanks

A: 

You can apply a CSS style to hide everything but what you want printed for media="print" using Javascript.

You can also load the page in another window or a [hidden] <iframe> and print that.

strager
I'm not sure I understand your answer, but there's no need to use javascript. Browsers repaint the page using the correct css when printing.
Alsciende
@Alsciende, I know that. I understood the question as wanting to print only a very small portion of the document, not the entire document. I meant he can insert the CSS rules for the print medium before printing starts so everything except that small portion is hidden.
strager
+1  A: 

You should use a separate css for the print media. This allows you to hide/show portions of the page when it gets printed.

html :

<div class="dont-print-that">
   blah
</div>
print this!

include:

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

print.css

.dont-print-that{display:none;}

The other solution is to open a new window with only the content you want to print. You could either do that in a popup or an iframe. Personally I find the CSS solution more elegant, but that's up to you.

marcgg
A: 

If you want to implement multiple "Print this section" features on a page, then print media stylesheets (described in other answers) are the way forward…

… but combine that with alternative stylesheets so you can switch to one for each section.

David Dorward