Javascript 如何在所有浏览器中禁用网页的打印屏幕功能?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5938466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:35:44  来源:igfitidea点击:

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

javascripthtmldocument-body

提问by ponds

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

使用以下我们可以禁用 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.

但是这些在 Mozilla、Chrome 和其他浏览器中不起作用。

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

有没有更好的方法来禁用打印屏幕/屏幕截图?

回答by ThiefMaster

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 :)

幸运的是没有浏览器,但 IE 允许你通过 JavaScript 访问剪贴板,所以你运气不好:)

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.

所以,结论是:停止做那样的废话。

回答by Brook Julias

Try onKeyPresscatch the PrtScr button, and return false. It's not pretty but I think that would work.

尝试onKeyPress捕捉 PrtScr 按钮,并返回 false。这并不漂亮,但我认为那会奏效。

回答by ch2

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