0

I would like to print only a table from a webpage whose id is "test1"

function printPage() { 
  $var = document.getElementById('test1');
  print($var); 
}

In print preview, the whole document is appearing and not the table. Most likely the entire page will be printed while all I want is my table to be printed.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
deepz
  • 225
  • 3
  • 13
  • 4
    that's not going to work. you need to define a `@media=print` stylesheet which hides everything except what you want to print. or clone that node into an iframe and then call that iframe's print(). – Marc B Apr 19 '13 at 18:38
  • possible duplicate of [how to print part of rendered html page in javascript?](http://stackoverflow.com/questions/1071962/how-to-print-part-of-rendered-html-page-in-javascript) –  Apr 19 '13 at 18:39
  • @Marc B - that should be an answer. – Floremin Apr 19 '13 at 18:40

1 Answers1

1

That's not going to work. you need to define a @media=print stylesheet which hides everything except what you want to print. or clone that node into an <iframe> and then call that iframe's print().

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Or they could use: `@media print { /* hide everything but your id here */ }` within their existing stylesheet if it doesn't take up too much space. – Joe Apr 19 '13 at 18:42