13

Env: jQuery, richfaces, all major browsers

How to disable printing options in the browser for certain pages (e.g. File-->Print Preview, Print)

djvg
  • 11,722
  • 5
  • 72
  • 103
user339108
  • 12,613
  • 33
  • 81
  • 112

2 Answers2

26

You cannot disable the actual buttons/menu items but you can use following in required pages to prevent printing:

<style type="text/css" media="print">
BODY {display:none;visibility:hidden;}
</style>
djvg
  • 11,722
  • 5
  • 72
  • 103
Abhijeet Pathak
  • 1,948
  • 3
  • 20
  • 28
  • 9
    You should mention that while this works superficially it is easy to circumvent. That it is impossible to completely stop people printing a page if it is shown to them. – AnnanFay Aug 18 '11 at 10:54
  • How would you circumvent this? – Rolando Nov 26 '13 at 03:06
  • 8
    @Rolando off the top of my head, screen shot, paste in image editor, print. Or if you want to really "hack" into it, just edit the CSS from the developers tools provided by the browser, and remove the CSS rule mentioned in this answer. – Munim Dec 30 '13 at 13:08
10

You can not disable the browser print buttons, however you can use print @media CSS to hide certain parts or whole page completely from printing. For example, you can use CSS such as this:

@media print {
  html, body {
    display: none;  /* hide whole page */
  }
}
Sarfraz
  • 377,238
  • 77
  • 533
  • 578