Can you add parameters inside a print() function in javascript

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();
}

Define a print stylesheet which will only display the table.

  • http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml
  • http://www.alistapart.com/articles/goingtoprint/

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)

Tags:

Javascript