The PrtScn button in IE does not behave like other browsers using java script

I use the following javascript code that blocks ordinary users (and not professionals, of course) from using the print screen and Ctrl + A and Ctrl + C in the browser. it works as expected in Firefox and Chrome, but sometimes it works on IE, and in other cases it fails. Please review the code if you can help a bit, it is possible that it will go wrong in IE. and why does it fail?

function disableselect(e) {
    return false;
}
function reEnable() {
    return true;
}
document.onselectstart = new Function("return false");
if (window.sidebar) {
    document.onmousedown = disableselect;
    document.onclick = reEnable;
}
function copyToClipboard() {
  // Create a "hidden" input
  var aux = document.createElement("input");
  // Assign it the value of the specified element
  aux.setAttribute("value", "You can no longer give print-screen. This is part of the new system security measure");
  // 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("You can no longer give print-screen. This is part of the new system security measure.");
}
$(window).keyup(function(e){
  if(e.keyCode == 44){
    copyToClipboard();
  }
}); 
$(window).focus(function() {
  $("body").show();
}).blur(function() {
  $("body").hide();
});
+4
source share
1 answer

I tested it and it works for me using Chrome, Firefox, IE11.

But if someone uses the Inspect Element to disable the CSS constraint, then they will disable it :)

+4
source

Source: https://habr.com/ru/post/1690271/


All Articles