How can we stop users to print webpage using different methods?
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?
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 ...
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With