0

Possible Duplicate:
Print <div id=printarea></div> only?

What's the easiest way to implement a button that prints the contents of a HTML document...

I want the print dialog box to appear on press of a button and to print the contents of a div.

Currently, I am using jQuery and HTML.

Community
  • 1
  • 1
user906568
  • 475
  • 2
  • 9
  • 21

3 Answers3

1

I would continue using your HTML and jQuery to trigger the print dialog along side a print media css file to filter what gets printed.

If it's just the content of one single div you want to print, simply hide everything else and have that as the only visible item in the print css.

Something a bit like this: http://jsfiddle.net/f2NHn/

Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
  • Although your general advice is good, using `display:none` as per your jsfiddle won't work. The * selector will match the html element and nothing inside it will display, no matter what the css of the individual elements. I suggest using `* { visibility:hidden }` and `visibility:visible` on the #content div, with appropriate positioning. Like this jsfiddle - http://jsfiddle.net/Agjqp/ – Alohci Sep 04 '11 at 18:53
0

in fact jquery's .html() function will encode html entities.

see and example here http://jsfiddle.net/7dQTD/

Hope it helps.

update: my example shows how to print the "html" content. If you don't want the html to be displayed "as is" just replace .text() with .html() in the example

Jonathan Liuti
  • 685
  • 5
  • 10
0

How about view->source and then file->print from the displayed source page?

Pete Wilson
  • 8,610
  • 6
  • 39
  • 51