最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I disable print-screen functionality for a webpage in all browsers? - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Apr 8, 2019 at 4:12 TrebledJ 8,9977 gold badges27 silver badges49 bronze badges asked May 9, 2011 at 14:41 pondsponds 2,0374 gold badges16 silver badges11 bronze badges 6
  • 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 Commented May 9, 2011 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 Commented May 9, 2011 at 14:50
  • 3 Even if you disable print screen, it is always possible to use a camera to take a picture to the monitor. – Enrique Commented May 9, 2011 at 14:57
  • 5 I'm staggered that IE allows this madness. – spender Commented May 9, 2011 at 14:58
  • 2 Quite simply if you want nobody to take it off your site, do not put it on. – Lee Kowalkowski Commented Nov 2, 2011 at 9:27
 |  Show 1 more comment

3 Answers 3

Reset to default 31

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.

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

window.addEventListener("keyup",kPress,false);
function kPress(e)
{ 
var c=e.keyCode||e.charCode; 
if (c==44) alert("print screen");
}
发布评论

评论列表(0)

  1. 暂无评论