Javascript 阻止用户对任何网页使用键盘的“Print Scrn”/“Printscreen”键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3130983/
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
Stop User from using "Print Scrn" / "Printscreen" key of the Keyboard for any Web Page
提问by Knowledge Craving
I am currently doing a project, in which I need to stop the user from taking the snapshot of any Web Page, for which he can use the "Print Scrn" / "Printscreen" key available in any of the normal keyboards.
我目前正在做一个项目,我需要阻止用户拍摄任何网页的快照,为此他可以使用任何普通键盘中可用的“Print Scrn”/“Printscreen”键。
I have been trying to find its solution, but in vain. If possible, I need to take into account of the "Screengrab" add-on of the Firefox browser, by stopping it also.
我一直试图找到它的解决方案,但徒劳无功。如果可能,我需要考虑Firefox 浏览器的“ Screengrab”附加组件,同时将其停止。
Any help is greatly appreciated, and I am using PHP (as server-side language) & jQuery for my project.
非常感谢任何帮助,我在我的项目中使用 PHP(作为服务器端语言)和 jQuery。
采纳答案by Dirk Vollmar
You can't disable screen grabbing from the Web browser, it would only be possible by installing additional software on the user's PC.
您无法禁用 Web 浏览器的屏幕抓取,只能通过在用户的 PC 上安装其他软件来实现。
There are some IRM (Information Rights Management) tools available that do that e.g. by protecting Windows/DirectX API calls and also monitoring video memory such as Oracle IRMor such as Microsoft's IRM technology.
有一些可用的 IRM(信息权限管理)工具可以做到这一点,例如通过保护 Windows/DirectX API 调用以及监视视频内存(如Oracle IRM或Microsoft 的 IRM 技术)。
Especially the latter might be of interest as there is also a Rights Management Add-on for Internet Explorer.
尤其是后者可能会引起人们的兴趣,因为还有用于 Internet Explorer的Rights Management Add-on。
But as other already said, any IRM/DRM technology is controversy and you should understand that it most often will limit or annoy your users.
但正如其他人已经说过的,任何 IRM/DRM 技术都是有争议的,您应该明白它通常会限制或惹恼您的用户。
回答by Marcelo Rocha
I hate the "it's not possible" sentence. Here's all solutions combined to help you:
我讨厌“这是不可能的”这句话。以下是所有可以帮助您的解决方案:
1- You can grab the solution from Haluk:
1- 您可以从 Haluk 获取解决方案:
<script type="text/javascript"> $(document).ready(function() {
$(window).keyup(function(e){
if(e.keyCode == 44){
$("body").hide();
}
}); });
</script>
HOWEVER, you hide body, but's already "printed" to clipboard. You can fire another event that copy some text to your clipboard, as you can see on this answer "Edit as of 2016" Click button copy to clipboard using jQuery, it's something like this:
但是,您隐藏了身体,但已经“打印”到剪贴板。您可以触发另一个将一些文本复制到剪贴板的事件,正如您在这个答案“Edit as of 2016”中看到的,使用 jQuery 单击按钮复制到剪贴板,它是这样的:
function copyToClipboard() {
// Create a "hidden" input
var aux = document.createElement("input");
// Assign it the value of the specified element
aux.setAttribute("value", "Você n?o pode mais dar printscreen. Isto faz parte da nova medida de seguran?a do sistema.");
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
alert("Print screen desabilitado.");
}
$(window).keyup(function(e){
if(e.keyCode == 44){
copyToClipboard();
}
});
This will block a part of your problem. If user focus on another object outside this windows he will be able to take screenshots. **But there's another solution to that as well, simply disable the hole body when window get's unfocused. Full solution, from your dear brazillian friend:
这将阻止您的问题的一部分。如果用户关注此窗口外的另一个对象,他将能够截取屏幕截图。**但还有另一种解决方案,只需在窗口未聚焦时禁用孔体即可。完整的解决方案,来自您亲爱的巴西朋友:
function copyToClipboard() {
// Create a "hidden" input
var aux = document.createElement("input");
// Assign it the value of the specified element
aux.setAttribute("value", "Você n?o pode mais dar printscreen. Isto faz parte da nova medida de seguran?a do sistema.");
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
alert("Print screen desabilitado.");
}
$(window).keyup(function(e){
if(e.keyCode == 44){
copyToClipboard();
}
});
$(window).focus(function() {
$("body").show();
}).blur(function() {
$("body").hide();
});
Here's the example working:
这是工作示例:
回答by Sjoerd
This is not possible.
这不可能。
回答by Pekka
Thankfully, this outrageous idea is not possible to implement reliably, neither the "disable screen grab" part nor the "disable user's Firefox extensions" one. And even if it were, as @kbok points out in his comment above, you don't have a rightto do this.
谢天谢地,这个离谱的想法不可能可靠地实现,无论是“禁用屏幕抓取”部分还是“禁用用户的 Firefox 扩展”部分。即使是这样,正如@kbok 在上面的评论中指出的那样,您也无权这样做。
The only way to protect your content online is copyright laws - mentioning those is often enough to scare people away from misusing it! - or not showing it at all.
保护您的在线内容的唯一方法是版权法 - 提及这些通常足以吓唬人们不要滥用它!- 或者根本不显示。
回答by ZX12R
Try this
尝试这个
$(document).keyup(function(e){
if(e.keyCode == 44) return false;
});
Hope it works
希望它有效
回答by Leo
You can change the contents of the clipboard using JavaScript or Flash. This already helps a bit.
您可以使用 JavaScript 或 Flash 更改剪贴板的内容。这已经有点帮助了。
回答by Piotr Kazu?
You can copy to clipboard something else, when user click key print screen. This is example and I copy user text.
当用户单击键打印屏幕时,您可以将其他内容复制到剪贴板。这是示例,我复制了用户文本。
<p id="test">test</p>
function copyToClipboard(elementId) {
// Create a "hidden" input
var aux = document.createElement("input");
// Assign it the value of the specified element
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
}
$(document).ready(function(){
$(window).keyup(function(e){
if(e.keyCode == 44){
copyToClipboard('test');
};
});
});
回答by Svish
Like @Sjoerd said, this is not possible.
就像@Sjoerd 所说,这是不可能的。
If it is pictures you want to protect, I suggest you for example display lower quality images that are watermarked instead and only display the non watermarked high quality ones when appropriate.
如果是您要保护的图片,我建议您例如显示带有水印的较低质量的图像,并在适当的时候仅显示未加水印的高质量图像。
But yeah... If you want them to be impossible to copy... don't put them online.
但是是的...如果您希望它们无法复制...请不要将它们放在网上。
回答by iJassar
There is no direct method to do that, however, there is a way to protect your content as much as possible from prnt scrn.
没有直接的方法可以做到这一点,但是,有一种方法可以尽可能保护您的内容免受 prnt scrn 的影响。
The idea is this:
这个想法是这样的:
make your content inaccessible if java is disabled, and use some script like Artist Scope's copy protect.
Detecting prnt scrn will send a message to the admin with the registered userinfo, this means that restricted content that is accessible by members only can benefit from this. sending IPaddresses sounds like a good idea, but banning IPs is not, so you won't gain a lot of benefit from that.
Once outside your website's window, your content will be covered with an overlay that can't be removed unless you get back to your website and activate it, which will re-activate the prnt scrn detection code mentioned in the previous point.
If the device is a mobile, you can either hide images, or as in my case, redirect to a "we're sorry" page.
snipping tooland other similar browser extensions and add-ons will be useless. except one tool that I have found called full page screen capture
- this tool captures web content after about 3 seconds from pressing button, which is enough time to dismiss the overlay and get back to your content
- a good turnaround is to start a counter when "dismiss overlay" is clicked that will need 5 seconds or more, ie. after this extension has already taken a snapshot
There's also an indirect method to prevent video capture, still working on it, will post it here or in my blog.
If your content is really that much worth it, users might still capture it using their cameras, there might be a method for that too! But I sill need to do some research before talking about it.
如果 Java 被禁用,则使您的内容无法访问,并使用一些脚本,如 Artist Scope 的复制保护。
检测 prnt scrn 将向管理员发送一条包含注册用户信息的消息,这意味着只有成员才能访问的受限内容才能从中受益。发送IP地址听起来是个好主意,但禁止 IP 则不然,因此您不会从中获得很多好处。
一旦离开您网站的窗口,您的内容将被覆盖,除非您返回您的网站并激活它,否则您的内容将无法删除,这将重新激活上一点中提到的 prnt scrn 检测代码。
如果设备是移动设备,您可以隐藏图像,或者像我一样重定向到“我们很抱歉”页面。
截图工具和其他类似的浏览器扩展和附加组件将毫无用处。除了我发现的一种称为全页屏幕截图的工具
- 此工具在按下按钮约 3 秒后捕获 Web 内容,这足以关闭叠加层并返回到您的内容
- 一个好的转变是在单击“关闭覆盖”时启动一个计数器,这将需要 5 秒或更长时间,即。在此扩展程序已经拍摄快照之后
还有一种防止视频捕获的间接方法,仍在研究中,将在此处或我的博客中发布。
如果您的内容真的那么值得,用户可能仍然使用他们的相机捕捉它,也可能有一种方法!但在谈论它之前,我还需要做一些研究。
I will be updating this postin my blog for other techniques that I've used/ will use for more protection. Please check this quiz(still under development) for a demo.
回答by SRKX
Why do you want to prevent the print screen?
为什么要防止打印屏幕?
If it's some photos you want to protect, you might want to put it in low resolution, and include some kind of copyright logo programmatically in php.
如果您想保护某些照片,您可能希望将其设置为低分辨率,并以编程方式在 php 中包含某种版权徽标。
I think that's pretty much it.
我想差不多就是这样。


