如何在 Javascript 中捕获打印屏幕事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10577515/
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-10-26 10:19:23  来源:igfitidea点击:

How to capture printscreen event in Javascript?

javascripthtmlscreenshotdom-events

提问by nsivaram90

I'm trying to write a web application which has some sensitive content in it. I have already prevented copy-and-paste. How do I detect when someone presses the printscreen key, so that the data may be hidden when that is pressed?

我正在尝试编写一个包含一些敏感内容的 Web 应用程序。我已经阻止了复制和粘贴。如何检测某人何时按下了打印屏幕键,以便在按下时隐藏数据?

Do not worry about mobile phones/cameras/ screen recording software, as they are not used in the environment.

不用担心手机/相机/屏幕录制软件,因为它们不在环境中使用。

回答by Peter Cullen

The short answer is, you can't reliably detect or interfere with the print screen function. This is not a browser function but a function of the user's system, so for most cases the event fires outside of the environment you're trying to detect it in. Neither html, css or javascript can listen for the event, or prevent its default action in a way that is dependable. You should re-think your strategy for protecting your content, and accept the reality that no matter what you do, there will always be way for people to "steal" it.

简短的回答是,您无法可靠地检测或干扰打印屏幕功能。这不是浏览器功能而是用户系统的功能,因此在大多数情况下,事件会在您尝试检测它的环境之外触发。 html、css 或 javascript 都无法侦听该事件,也无法阻止其默认设置以可靠的方式采取行动。您应该重新考虑保护您的内容的策略,并接受这样一个现实:无论您做什么,人们总会有办法“窃取”它。

EDIT:

编辑:

I was thinking, you could write a java applet that detected the print screen event firing as java may have access to system events. But I haven't bothered looking into how you could do this because the function depends on two things - the user having java installed and enabled in their browser, and the java applet having the security permissions granted to it to go snooping the system events.

我在想,您可以编写一个检测打印屏幕事件触发的 java 小程序,因为 java 可能可以访问系统事件。但是我没有费心研究如何做到这一点,因为该功能取决于两件事 - 在浏览器中安装并启用了 java 的用户,以及具有安全权限的 java 小程序,可以监听系统事件。

Just out of interest: https://stackoverflow.com/a/29965963/4933137

只是出于兴趣:https: //stackoverflow.com/a/29965963/4933137