4

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
nsivaram90
  • 141
  • 1
  • 1
  • 11
  • 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 May 14 '12 at 04: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 May 14 '12 at 04:38
  • 2
    Even if you could, user could make the window with sensitive content out of focus and and then print screen. – Eleeist May 14 '12 at 04:53
  • 1
    Or the user could disable javascript. You can't control these things. – dtbarne May 17 '12 at 04:43

1 Answers1

5

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

Peter Cullen
  • 896
  • 1
  • 11
  • 23