6

Using the following we can disable print-screens or screenshots in Internet Explorer:

<body onload=setInterval("window.clipboardData.setData('text','')",2) 

oncontextmenu="return false" onselectstart="return false">

But these don't work in Mozilla, Chrome and other browsers.

Is there a better way to disable print-screens/screenshots?

TrebledJ
  • 8,713
  • 7
  • 26
  • 48
ponds
  • 2,017
  • 4
  • 16
  • 11
  • 10
    ok, **yay** you disabled print screen. what about ms windows screen snip and anything else that gets screen captures. im not sure what the point is to block it... – Naftali May 09 '11 at 14:48
  • 13
    That's some nasty code that would really p**s me off. What if I'm using the clipboard for some other purpose? You just destroyed my clipboard for all apps. Besides, manipulating the clipboard without user interaction is not possible in other browsers and requires transparent Flash content. Please, please rethink what you are doing. If you don't want it copied, don't put it on the web. – spender May 09 '11 at 14:50
  • 2
    Even if you disable print screen, it is always possible to use a camera to take a picture to the monitor. – Enrique May 09 '11 at 14:57
  • 5
    I'm staggered that IE allows this madness. – spender May 09 '11 at 14:58
  • 2
    Quite simply if you want nobody to take it off your site, do not put it on. – Lee Kowalkowski Nov 02 '11 at 09:27
  • This other question about how Netflix prevents screenshots may be of interest to people arriving here: https://stackoverflow.com/q/63175756 – Lucio Paiva Sep 30 '21 at 09:56

3 Answers3

30

What makes you think it's your decision if people should be able to take screenshots or not?

Luckily no browser but IE allows you to access the clipboard via JavaScript so you are out of luck :)

By the way, if I visited your site and it messed up my clipboard (it overwrites anything in there, even if it's unrelated to your site) - I might have stored something in it that I've just cut from some file and I was going to paste in a different file and thanks to your site it would now be lost.

So, the conclusion is: Stop doing crap like that.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • 4
    Quite often things like these are dictated by a client, despite our warning them against it. If they insist on the right to shoot themself in the foot... – ProfK Jul 19 '12 at 07:56
  • 6
    the OP's question was to suggest a better idea... "Stop doing crap like that." IS a better idea. – Wim Ombelets Apr 04 '14 at 10:05
  • Security requirements for POPIA and GPDR nullify your argument, it is necessary today to block print screens of any sensitive information that could be copied or saved down. – Marc Magon Jul 20 '21 at 07:03
  • @ThiefMaster From a programmatic point of view, and design and usage view, I am in agreement with you - From a business security and law perspective however, I am not :) I value your opinions, but I do have targets and requirements to code for as well, Capturing and hijacking the clipboard not the best answer, but it's not a stop doing rubbish like that - it's a how to do the rubbish in a way that's not intrusive. Thank you for your views :) – Marc Magon Jul 22 '21 at 09:27
-2

It's an O.S. function, as well as a page function, and a print function so there are a few things you need to do - The steps below are specific for windows, however can be implemented in any O.S. with the same concept -

  1. Disable the print screen at an O.S. Level
Here are the steps of disable Print Screen key:

1.Copy the following registry to notepad and saved as a .reg file.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,00,00,2a,e0,00,00,37,e0,\
00,00,54,00,00,00,00,00
2.Apply the registry 
3.Sign out and sign in again.

Then you need to block the browsers capability of capturing screens in the cases where chrome or edge or firefox have extensions that enhance print screens - And for extra measure, disable right click (I put it on document but you can put it per DOM

  document.addEventListener('contextmenu', 
                        event => event.preventDefault());
                        
                        window.addEventListener("keyup",kPress,false);
                    function kPress(e)
                    { 
                    var c=e.keyCode||e.charCode; 
                    if (c==44) event.preventDefault();
                    }

Then as an extra, to disable printing and items, you need to mark the print media as display none

@media print {
               .noprint {
                  visibility: hidden;
               }
            }

And if you want to be POPIA/GDPR compliant, you have to disable things like pdf download, object references and things so as a bonus item, Use PDF.js to render the pdf as html with full control over the rendering of the PDF, download and printing using the above

This reference allows password entries and successfully gave us full control over all features for capturing or saving information from protected sites

https://usefulangle.com/post/22/pdfjs-tutorial-2-viewing-a-password-protected-pdf

Marc Magon
  • 713
  • 7
  • 11
-9
window.addEventListener("keyup",kPress,false);
function kPress(e)
{ 
var c=e.keyCode||e.charCode; 
if (c==44) alert("print screen");
}
ch2
  • 1
  • 12
    Welcome to Stack Overflow! Rather than only post a block of code, please *explain* why this code solves the problem posed. Without an explanation, this is not an answer. – Martijn Pieters Nov 13 '12 at 15:34
  • 2
    you can't disable print screen. so please test your code before posting it – juhi Apr 04 '14 at 09:38