Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop user from printing webpages? using javascript or jquery

How can we stop users to print webpage using different methods?

  1. Disabling Right Click
  2. Disabling CtrlP combination of keys
  3. Right click -> print

Is there any way to stop printing webpages?

Can we handle these 3 events using javascript. Or we can say . if user will do any of these events. then i want to run my other code .Is this possible?

like image 448
Gourav khanna Avatar asked Jul 11 '11 08:07

Gourav khanna


People also ask

How to stop user from printing webpages?

How to stop user from printing webpages? using javascript or jquery 1 Disabling Right Click 2 Disabling Ctrl P combination of keys 3 Right click -> print More ...

Is it possible to disable the print event of a website?

Yes you can do it with JavaScript This script will disable everything from which a user can print like from the console or right clicking or ctrl+p And use it with css @media print {body {display:none;}} For a extra security. Using Javascript code you can block any event of browser.

Is there a way to prevent the browser from printing text?

You can intercept certain key presses etc and cancel them using script but when the user has script disabled then there's no prevention. Also, the print functionality is built into the actual browser itself, you can't actually prevent this.

How to prevent users from printing when rendering a document?

If you render something onto the browser of the user, it becomes in the control of the user. You can not resist the user from printing. If you wish some information to be shown to the user, and you do not want the user to be able to print, you can use something like a PDF and securing it against printing.


2 Answers

As has already been noted, you cannot do this. However, one commonly used trick is to try and hide all the page content if it's being printed:

<style type="text/css" media="print">
    body { visibility: hidden; display: none }
</style>

But this is not guaranteed to work, and it's easy to get around if you have even a vague idea what you're doing.

like image 146
James Allardice Avatar answered Nov 20 '22 21:11

James Allardice


A webpage on a user's machine is out of your control. A user can do whatever he or she wants to do, however you can serve a PDF and disable printing that PDF. Still, if I have to print some thing I will find a way to print it.

like image 20
Kumar Avatar answered Nov 20 '22 23:11

Kumar