我一直在使用以下javascript代码阻止普通用户(当然不是专业人士)使用print screen& Ctrl + A&在浏览器上按Ctrl + C. 它在Firefox& Chrome但它有时适用于IE,有时则失败。如果您可以帮助解决IE上可能出现的问题,请查看代码。为什么失败?
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();
});
答案 0 :(得分:4)
我测试了它,它适用于我使用Chrome,Firefox,IE11。
但是,如果有人使用Inspect Element来禁用CSS限制,那么他将禁用它:)