Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 460
Knowledge Craving Avatar asked Jun 28 '10 08:06

Knowledge Craving


People also ask

How do I restrict the Print Screen button on a website?

Click "Edit" and then "Select All." Right-click the selected text and click "Copy." Open the HTML document for which you would like to disable the print screen ability. Paste the code anywhere between the head tags ( and ) of the document. Save the document.

How do I disable the PrtSc key?

Click on the "Keyboard" icon to open a window. Find the "FilterKey" option and turn it off.

What is the use of Print Screen key in keyboard?

Locate the Print Screen key on your keyboard. It's usually in the upper-right-hand corner, above the “SysReq” button and often abbreviated to “PrtSc.” Press the main Win key and PrtSc at the same time. This will take a screenshot of the entire current screen.


1 Answers

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

like image 163
Marcelo Rocha Avatar answered Oct 02 '22 15:10

Marcelo Rocha