How to disable printscreen with javascript?

GoobyPrs picture GoobyPrs · Oct 10, 2014 · Viewed 25.4k times · Source

I want to make function in javascript which change value of clipboard after the printscreen was used. Is that possible?

$(document).keyup(function(e){ if(e.keyCode == 44) //change clipboard value code });

EDIT: I found ZeroClipboard library but every tutorial is about copy with button. I want just change the value of clipboard.

Answer

user11877466 picture user11877466 · Aug 5, 2019

There is another way to disable Print Screen in your website (it worked for my website). Click here to go to my Pen (Codepen.io). Here is also a snippet:

document.addEventListener("keyup", function (e) {
    var keyCode = e.keyCode ? e.keyCode : e.which;
            if (keyCode == 44) {
                stopPrntScr();
            }
        });
function stopPrntScr() {

            var inpFld = document.createElement("input");
            inpFld.setAttribute("value", ".");
            inpFld.setAttribute("width", "0");
            inpFld.style.height = "0px";
            inpFld.style.width = "0px";
            inpFld.style.border = "0px";
            document.body.appendChild(inpFld);
            inpFld.select();
            document.execCommand("copy");
            inpFld.remove(inpFld);
        }
       function AccessClipboardData() {
            try {
                window.clipboardData.setData('text', "Access   Restricted");
            } catch (err) {
            }
        }
        setInterval("AccessClipboardData()", 300);
body {
  background-color: #00FF00;
}
<html>
    <head>
      <title>Disable Print Screen</title>
    </head>
  <body>
      <h2>Print screen is disabled</h2>
      <p>Click anywhere on green background and try to "print screen" the content (and then see the result in Paint or simulair software)
  </body>
</html>

Click here for original code