Stop User from using “Print Scrn” / “Printscreen” key of the Keyboard for any Web Page

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

Leave a Comment