javascript 使用javascript禁用打印屏幕键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24739519/
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
disable print screen key using javascript
提问by AtmiyaDas2014
I'm trying to disable the print screen key on my website. This is what I have so far:
我正在尝试禁用我网站上的打印屏幕键。这是我到目前为止:
<SCRIPT type="text/javascript">
focusInput = function()
{
document.focus();
};
processKeyEvent = function(eventType, event)
{
if (window.event)
{
event = window.event;
}
if(event.keyCode == 44)
{
alert("Photos are copyright 2011");
return(false);
}
}
processKeyUp = function(event)
{
processKeyEvent("onkeyup", event);
};
processKeyDown = function(event)
{
processKeyEvent("onkeydown", event);
};
document.onkeyup = processKeyUp;
document.onkeydown = processKeyDown;
</SCRIPT>
But this isn't working. How can I disable the print screen key to prevent users from making a snapshot of my site?
但这不起作用。如何禁用打印屏幕键以防止用户制作我网站的快照?
回答by Jan Hudec
You can't. It's beyond your control, because print screen (unlike the in-browser print icon/Ctrl-P) is nota browser feature but a system feature.
你不能。这超出了您的控制,因为打印屏幕(与浏览器中的打印图标/Ctrl-P 不同)不是浏览器功能而是系统功能。
Besides, any such attempt is futile and ultimately counter-productive. Because you will piss off the Joe Random User who wants to print the page because they want to read it on the bus or whatever and won't stop somebody who wants to abuse the images as they can always take advantage of the fact that the device is ultimately under their physical control and no software in the world can do anything against modification of the device (e.g. using a monitor with screen capture).
此外,任何此类尝试都是徒劳的,最终会适得其反。因为你会惹恼想要打印页面的 Joe Random 用户,因为他们想在公共汽车上阅读它或其他任何东西,并且不会阻止想要滥用图像的人,因为他们总是可以利用设备最终都在他们的物理控制之下,世界上没有任何软件可以阻止修改设备(例如使用带屏幕截图的监视器)。