Can you add parameters inside print () function in javascript

I am looking for a way to add parameters to the print function, because I only have to print the table, and when I warn the table, it shows me the correct value, but when I print it, you print the whole page.

My code

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

If I alert(aa) , it gives me the value of the record, then I print(aa) it gives me the whole page. so I tried print(aa) and aa.print and it does not work.

Does anyone know a solution for this?

+4
source share
3 answers

Print style sheets are good, but you can still do it in Javascript. Just pass your print value 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(); } 
+11
source

Define a print style sheet in which only the sheet will be displayed.

It does not need to be dynamic.

Just define those sections that you do not want to see as display: none (as indicated in the alistapart article)

+6
source

No, you can’t.

What you can do is dynamically change the print and display stylesheet: there are no elements that you do not want.

YUI StyleSheet can help with this.

+1
source

All Articles