tags:

views:

40

answers:

3

Hi,

how can i print a web page? more exactly i want to print only a table in the web-page.

i found out how to print all the page, some thing like this: <A HREF="javascript:window.print()">

i realy don't know javascript. can i modify this to javascript:table.print()?

thanks, Sebastian

+3  A: 

You could create a stylesheet (that is used for printing) that only shows the table.

Include it as:

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

(This would solve printing only the table, if thats all you wanted them to be able to print out)

Css would be something like:

* {
  display:none;
}
table {
  display:block;

}

Or

div, p (list elements here){
  dislay:none;
}

Or

* {
  visibility:hidden;
}
table,tr,td {
  visibility:visible;

}
+1 I was just writing the same
jigfox
Typed it out quickly as I knew someone would come up with it too.
thank's for your reply. what should i write in the css file?
sebastian
Added it to my answer
`table { display:block; }` will break in standards-confirming browsers. The standard display type of tables is `table`. Also the descendants will need to be "re-displayed", too.
RoToRa
Was just a quick answer as i don't know what elements are showing
i have the same problem here as below. the table i want to print is generated after a form is completed. i have other tables and items on the page that need to be visible.
sebastian
A: 

You can use a CSS style sheet to print what you want by adding it to your to your page and setting the media attribute of the stylesheet tag to print. So to print your table you could hide all the elements on the page apart from your table.

matpol
A: 

A simple solution is to generate a web page with only the element(s) you want to print and call window.print()

(there is no table.print)

David
that's a bit harder, i'm using joomla, and the content that i want to make available for print is a table that only appears after a form is completed.
sebastian