59

I am currently doing a project, in which I need to stop the user from taking the snapshot of any Web Page, for which he can use the "Print Scrn" / "Printscreen" key available in any of the normal keyboards.

I have been trying to find its solution, but in vain. If possible, I need to take into account of the "Screengrab" add-on of the Firefox browser, by stopping it also.

Any help is greatly appreciated, and I am using PHP (as server-side language) & jQuery for my project.

Knowledge Craving
  • 7,791
  • 12
  • 46
  • 90
  • 14
    You also need to take into account, at least, Cmd+Alt+3, Cmd+Alt+4, Cmd+Alt+Shift+3, Cmd+Alt+Shift+4, Grab.app, WebSnapper, SnapsPro, the humble Print dialog and a myriad of other tools for Mac users. And let's not even get started with all the other Windows and Linux ways there are to take screenshots. – deceze Jun 28 '10 at 08:36
  • 19
    Okay, I apologize in making such a foolish question. **But then can't I ask any such question as to which I didn't know at all?** – Knowledge Craving Jun 28 '10 at 10:23
  • 18
    This is a perfectly legitimate question regardless of the feasibility of the request. We have all faced requirements that are dubious at best. Answering questions such as this helps explain why such requirements can not, nor should not, be implemented. – etc Jun 28 '10 at 10:39
  • 1
    Thanks for supporting, as this question just showed me what sort of sin I have performed asking here! – Knowledge Craving Jun 28 '10 at 10:45
  • 23
    Down voting this question is the wrong thing to do. The question is fine and a lot of non webby people ask similar questions (see also popup/unders) Clearly the answer is "don't and you cannot anyway" however punishing the OP does no one any good. – Loofer Jun 28 '10 at 11:50
  • 4
    Wow, what a vote swing on this question! Is everybody just following the mood of the latest comment? (For the record, I voted neither way, which expresses exactly how I feel about this question.) – deceze Jun 29 '10 at 01:33
  • Perhaps it's because this question has been asked 935835 times before... – NibblyPig Jun 29 '10 at 09:01
  • 1
    The last time such idiotic websites happened my way, and I needed to print something (and surprise! The print button was disabled too!), I ran the damned site in a virtual machine, and took a copy from that. As a result, I was able to discuss results with a group of people who needed to look at the printout rather than having the group huddle around my computer which, thanks to the website in question, would process each click oh so very slowly. Printing it saved hours of my time. (And before you ask... Yes, that was perfectly legal). – Arafangion Jun 29 '10 at 05:05
  • 1
    Good question. I apologize on behalf of the try-hards who try to haymaker you. The question is a good question. It cannot be done 100% and may cost you in regards to UX. I still admire the question because I once wanted to know this. I also admire it because look at the tons of ideas that spilled out of very talented developers' brains. I have no idea why some experienced devs can be so harsh on the new guys. The site was designed to learn and grow, but some make people run away before they get going. Sad. Thanks for your question! I loved the ideas that it brought forward. Added value to SO – DavidG Apr 12 '20 at 19:27

11 Answers11

53

I hate the "it's not possible" sentence. Here's all solutions combined to help you:

1- You can grab the solution from Haluk:

<script type="text/javascript"> $(document).ready(function() {
    $(window).keyup(function(e){
      if(e.keyCode == 44){
        $("body").hide();
      }

    }); }); 
</script>

HOWEVER, you hide body, but's already "printed" to clipboard. You can fire another event that copy some text to your clipboard, as you can see on this answer "Edit as of 2016" Click button copy to clipboard using jQuery , it's something like this:

function copyToClipboard() {
  // Create a "hidden" input
  var aux = document.createElement("input");
  // Assign it the value of the specified element
  aux.setAttribute("value", "Você não pode mais dar printscreen. Isto faz parte da nova medida de segurança do sistema.");
  // Append it to the body
  document.body.appendChild(aux);
  // Highlight its content
  aux.select();
  // Copy the highlighted text
  document.execCommand("copy");
  // Remove it from the body
  document.body.removeChild(aux);
  alert("Print screen desabilitado.");
}

$(window).keyup(function(e){
  if(e.keyCode == 44){
    copyToClipboard();
  }
}); 

This will block a part of your problem. If user focus on another object outside this windows he will be able to take screenshots. **But there's another solution to that as well, simply disable the hole body when window get's unfocused. Full solution, from your dear brazillian friend:

function copyToClipboard() {
  // Create a "hidden" input
  var aux = document.createElement("input");
  // Assign it the value of the specified element
  aux.setAttribute("value", "Você não pode mais dar printscreen. Isto faz parte da nova medida de segurança do sistema.");
  // Append it to the body
  document.body.appendChild(aux);
  // Highlight its content
  aux.select();
  // Copy the highlighted text
  document.execCommand("copy");
  // Remove it from the body
  document.body.removeChild(aux);
  alert("Print screen desabilitado.");
}

$(window).keyup(function(e){
  if(e.keyCode == 44){
    copyToClipboard();
  }
}); 

$(window).focus(function() {
  $("body").show();
}).blur(function() {
  $("body").hide();
});

Here's the example working:

Here i try to unfocus the window, on unfocus i hide content and show modal

Community
  • 1
  • 1
Marcelo Rocha
  • 760
  • 6
  • 7
  • I'v posted this months ago with my another facebook account. Anyway to change this answer to my current Facebook account? – Marcelo Agimóvel Mar 10 '17 at 13:54
  • 1
    Cool solution. Thanks. But it still has few flaws: Combination Win + Print screen. And of course, no one could prevent screenshotting simply by camera :) – Oleksandr_DJ Mar 14 '17 at 12:33
  • In Windows 10 IE 11, I get an alert that says "Do you want to allow this web page to access your clipboard?...". This is unacceptable for our client. So it seems there isn't a way to do this for us. – BBaysinger May 10 '18 at 00:43
  • 1
    For years I'v been saying developers should block IE. IE has been our nightmare and the chains that holded internet evolution for years . But here's a partial solution: show a message that user should allow copy/paste and show a huge text with symbols that he must copy and paste on a textbox. And recomend others browsers to user to avoid complications. Did I got too far? – Marcelo Agimóvel May 11 '18 at 13:13
  • I will suggest to use the "mouseover" instead the focus. $(window).mouseover(function () { $("body").show(); }).mouseout(function () { $("body").hide(); }); – Cédric Boivin Dec 12 '18 at 21:29
  • Your solution works but as @Oleksandr_DJ said there's flaws where you can use win+print and still able to screenshot it. Is there any possible way to disable that as well? – Daredevil Feb 18 '19 at 03:14
45

This is not possible.

Sjoerd
  • 68,958
  • 15
  • 118
  • 167
  • 5
    And if it were, it would be circumvented quite quickly. – Patrick Hendricks Jun 28 '10 at 08:33
  • 23
    The "print screen" key is an OS functionnality, and you have absolutely no right to alter its behaviour from a web page. This is like installing a software on the hard drive. Generally speaking, there is no real way to prevent an user from downloading the content of a website. You can just make it a little more difficult, but it would only be a matter of time. – slaphappy Jun 28 '10 at 08:34
  • 3
    In general: at some point the data must be displayed to the user. At that point, any determined user can capture it. If nothing else, there are devices that will sit between your PC and monitor, completely seperate from the PC and record anything sent to the monitor. – Matthew Scharley Jun 28 '10 at 08:36
  • 1
    Or they can use a camera, which may be totally unattached to any computer. They could even use a camera which records on film without any digital components at all; no way to stop that other than to never show the information to the user at all. – Donal Fellows Jun 28 '10 at 08:45
  • Such a restriction would be so annoying to users that they would probably never go back to your page again. That would prevent them from printing, but I don't think that's what you want. BTW writing a code snippet that downloads a page is as easy as WebClient.DownloadString (if you write .NET) or any of the myriad equivalents in other languages – Panagiotis Kanavos Jun 28 '10 at 08:47
  • 4
    @JSmaga That'll be the most single-purpose OS ever: "Features: **Can't take screenshots!** " ;D – deceze Jun 28 '10 at 09:12
  • @deceze In 6 months you can release the service pack 1 including the "Anti copy-paste feature" – SRKX Jun 28 '10 at 10:18
  • 1
    @deceze @JSmaga well.... It still would be better than Vista! http://xkcd.com/528/ – Pekka Jun 28 '10 at 15:01
  • 4
    Even with an OS without screenshot abilities, you could still put the screen on a scanner or take a photo of it :p – Svish Jun 28 '10 at 21:31
  • @Svish your comment was one of the funniest I have read on SO – Bhushan Apr 20 '13 at 06:07
  • Is this even consider an answer? – Ubi hatt May 21 '19 at 13:53
39

You can't disable screen grabbing from the Web browser, it would only be possible by installing additional software on the user's PC.

There are some IRM (Information Rights Management) tools available that do that e.g. by protecting Windows/DirectX API calls and also monitoring video memory such as Oracle IRM or such as Microsoft's IRM technology.

Especially the latter might be of interest as there is also a Rights Management Add-on for Internet Explorer.

But as other already said, any IRM/DRM technology is controversy and you should understand that it most often will limit or annoy your users.

Dirk Vollmar
  • 161,833
  • 52
  • 243
  • 303
  • 4
    I wouldn't say IRM is a "controversy". On the internet it is foolish to even consider it, but on a corporate environment it makes sense. Companies have IRM installed in every computer, and for a good reason. It sends a clear message to employees: "This data is sensitive". If it isn't trivial to copy the data, the employee wouldn't try further. – Kobi Jun 29 '10 at 05:20
  • 2
    @Chris - "Never attribute to malice that which is adequately explained by stupidity". If a hostile employee can see it she can steal it, however, IRM is very efficient in restricting data and preventing *unintentional* data leaks, and makes a good way of marking sensitive documents. – Kobi Jul 09 '10 at 14:25
  • Thank you for making it clear how user-hostile and poorly-received something to accomplish this would be. – seagull Mar 15 '16 at 12:28
  • how netflix does that..no screnshot no printscreen screen record screensharing using app like skype..everything bocked there how – rahul cp May 23 '20 at 19:34
16

Thankfully, this outrageous idea is not possible to implement reliably, neither the "disable screen grab" part nor the "disable user's Firefox extensions" one. And even if it were, as @kbok points out in his comment above, you don't have a right to do this.

The only way to protect your content online is copyright laws - mentioning those is often enough to scare people away from misusing it! - or not showing it at all.

Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • Mentioning copyright laws is frequently enough??? Says who? Millions of people across the globe steal media copyrighted by others. US protections do not suffice overseas. It's a federal crime with steep penalties including large six-digit fines and several years in jail. It's not an outrageous idea. Simply one from a new developer trying to help protect media he or his clients own. You have a right to do whatever you want with your website in regards to protection. UX may come into play. Not everyone can afford litigating copyright violations. Even if they could win, it takes time & money. – DavidG Apr 12 '20 at 19:19
  • Several large tech companies, who I will refrain from naming, have stolen patented ideas and locked the patent up in court for years and spent millions of dollars to fight until little guy has to leave his prize. – DavidG Apr 12 '20 at 19:21
14

Try this

$(document).keyup(function(e){
  if(e.keyCode == 44) return false;
});

Hope it works

ZX12R
  • 4,594
  • 6
  • 36
  • 53
6

You can change the contents of the clipboard using JavaScript or Flash. This already helps a bit.

Leo
  • 1,583
  • 3
  • 16
  • 23
4

There is no direct method to do that, however, there is a way to protect your content as much as possible from prnt scrn.

The idea is this:

  1. make your content inaccessible if java is disabled, and use some script like Artist Scope's copy protect.

  2. Detecting prnt scrn will send a message to the admin with the registered user info, this means that restricted content that is accessible by members only can benefit from this. sending IP addresses sounds like a good idea, but banning IPs is not, so you won't gain a lot of benefit from that.

  3. Once outside your website's window, your content will be covered with an overlay that can't be removed unless you get back to your website and activate it, which will re-activate the prnt scrn detection code mentioned in the previous point.

  4. If the device is a mobile, you can either hide images, or as in my case, redirect to a "we're sorry" page.

  5. snipping tool and other similar browser extensions and add-ons will be useless. except one tool that I have found called full page screen capture

    • this tool captures web content after about 3 seconds from pressing button, which is enough time to dismiss the overlay and get back to your content
    • a good turnaround is to start a counter when "dismiss overlay" is clicked that will need 5 seconds or more, ie. after this extension has already taken a snapshot
  6. There's also an indirect method to prevent video capture, still working on it, will post it here or in my blog.

  7. If your content is really that much worth it, users might still capture it using their cameras, there might be a method for that too! But I sill need to do some research before talking about it.

I will be updating this post in my blog for other techniques that I've used/ will use for more protection. Please check this quiz (still under development) for a demo.

iJassar
  • 119
  • 1
  • 14
4

Like @Sjoerd said, this is not possible.

If it is pictures you want to protect, I suggest you for example display lower quality images that are watermarked instead and only display the non watermarked high quality ones when appropriate.

But yeah... If you want them to be impossible to copy... don't put them online.

Svish
  • 138,188
  • 158
  • 423
  • 589
  • 7
    I don't like this term "not possible"... of all the things in the universe this is not something I would say is "not possible". I think the word unfeasible is better suited. Maybe I’m being pedantic, but I just don't like us, as the human race, selling ourselves short. Someone could do it if they really wanted. Hence... entirely possible. – 4imble Jun 28 '10 at 13:00
  • 3
    Although you don't like, there are many imposible things. And this is one of those. – Hernán Eche Jun 28 '10 at 13:34
  • 2
    Yeah, how on earth would you make that impossible? If it's on the screen, it's nothing you can do. How would you prevent someone from taking a camera and shooting a photograph of the screen for example? – Svish Jun 28 '10 at 20:08
  • It is "not possible"... if it can be viewed, it can be copied in some fashion. – nokturnal May 23 '12 at 14:50
4

You can copy to clipboard something else, when user click key print screen. This is example and I copy user text.

<p id="test">test</p>

function copyToClipboard(elementId) {

  // Create a "hidden" input
  var aux = document.createElement("input");

  // Assign it the value of the specified element
  aux.setAttribute("value", document.getElementById(elementId).innerHTML);

  // Append it to the body
  document.body.appendChild(aux);

  // Highlight its content
  aux.select();

  // Copy the highlighted text
  document.execCommand("copy");

  // Remove it from the body
  document.body.removeChild(aux);

}
$(document).ready(function(){
    $(window).keyup(function(e){
      if(e.keyCode == 44){
        copyToClipboard('test');
      };
    });
});
Piotr Kazuś
  • 306
  • 2
  • 9
2

Why do you want to prevent the print screen?

If it's some photos you want to protect, you might want to put it in low resolution, and include some kind of copyright logo programmatically in php.

I think that's pretty much it.

SRKX
  • 1,736
  • 19
  • 39
1

Here is another solution:

<script type="text/javascript"> $(document).ready(function() {
    $(window).keyup(function(e){
      if(e.keyCode == 44){
        $("body").hide();
      }

    }); }); </script>

This is similar to @ZX12R's solution. The upside is this code will work even if the print screen catching software is a 3rd party tool (eg snagIt).

You can replace $("body").hide(); with something which will suit you better. For instance you can hide all the pictures $("img").hide(); and maybe show them back a second later.

The downside is it will not work if the web page is not the active window.

Haluk
  • 1,993
  • 2
  • 26
  • 34
  • 7
    I am pretty sure the "print screening" has already occurred before the keyup event is fired... – nokturnal May 23 '12 at 15:43
  • 1
    Can also use the Snipping tool or similar, or just press the print screen key without the window active, and the webpage won't even get the event. – Svish May 23 '12 at 20:38
  • 1
    Unfortunately this will not work on OS X since the key combo is completely different. – Fizzix Aug 23 '15 at 12:56