How to capture printscreen event in Javascript?

孤街醉人 提交于 2020-01-04 03:13:11

问题


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?

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


回答1:


I went googling for the information and I hope the 2 links below will be able to assist you.

http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/0778d7f2-84d3-471e-9211-337bd7e94f49

http://www.webdeveloper.com/forum/archive/index.php/t-21431.html




回答2:


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.

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.

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



来源:https://stackoverflow.com/questions/10577515/how-to-capture-printscreen-event-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!