tags:

views:

1840

answers:

4

Hi guys i am looking for a way to add parameters on a print function, cause i have to print only the table and when i alert the table it shows me the correct value but when i am printing it prints the entire page.

my code is

aa = document.getElementById('tablename').innerHTML

if i alert(aa) it gives me the write value then i print(aa) it give me the entire page. so i tried print(aa) and aa.print and it doesn't work.

does anyone know the solution for this.

A: 

No, you can't.

What you could do is dynamically modify a print media stylesheet and display: none the elements you do not want.

YUI StyleSheet might help with that.

David Dorward
+6  A: 

Define a print stylesheet which will only display the table.

There's no need for it to be dynamic.

Simply define those sections you don't wan to see as display:none (as stated in the alistapart article)

altCognito
There might be a need for it to be dynamic - it depends if that is the one and only view of the page that will ever be printed.
David Dorward
Generally speaking I'd consider this a bad sign, maybe a sloppy design. It should be that you're just hiding menus and sometimes ads (I wish anyway). All the other stuff, people generally keep in a print out (headers, footers to retain copyrights and branding)
altCognito
+1  A: 

Print stylesheets are nice, but you can still accomplish this in Javascript. Just pass your value to be printed to the following function...

function printIt(printThis) {
  var win = window.open();
  self.focus();
  win.document.open();
  win.document.write('<'+'html'+'><'+'body'+'>');
  win.document.write(printThis);
  win.document.write('<'+'/body'+'><'+'/html'+'>');
  win.document.close();
  win.print();
  win.close();
}
Josh Stodola
A: 

@Josh Stodola: You're a lifesaver! Yours should be promoted as THE answer for this thread.

I do owe you a beer and a slice of pepperoni pizza, pal. Great stuff indeed!

WeMoecke