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.
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.
Share Improve this question edited Sep 6, 2019 at 14:35 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 14, 2012 at 4:29 nsivaram90nsivaram90 1411 gold badge1 silver badge11 bronze badges 4- 2 I don't think there is any way to do that. And print-screen is an OS Process, you should rather look into disabling the key in the User's OS – linuxeasy Commented May 14, 2012 at 4:33
- printscreen key depends on your OS. for example Mac doesn't have it at all, Linux implements differently from Windows too - also there are other screen capture methods & utilities, so you will never truly be safe. I mean I could just use a pen & write it down anyway. or I could save the page. – RiquezJP Commented May 14, 2012 at 4:38
- 2 Even if you could, user could make the window with sensitive content out of focus and and then print screen. – Eleeist Commented May 14, 2012 at 4:53
- 1 Or the user could disable javascript. You can't control these things. – dtbarne Commented May 17, 2012 at 4:43
1 Answer
Reset to default 5The 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./a/29965963/4933137