我复制并自定义了一个从过去的stackoverflow讨论中获取的脚本。现在我可以阻止"打印屏幕"使用当前的组合键:" ctrl + alt + printscr" ," ctrl + printscr"和" alt + printscr"。但是在我保存了我的博客模板之后,我做了一些非常有效的测试:脚本真的很棒..但不像预期的那样,我遇到了两个问题:
我不熟悉javascript语言,所以我可能犯了一些错误。我拍了一张照片,向你展示问题的本质。
PS:我的布局完全响应,我从来没有遇到过元素自动对齐的问题。然后我尝试删除最新的JavaScript,并再次完美。可能我在代码中犯了一些未知错误。
以下是代码:
<script language='JavaScript'>
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 printscreen. 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("Print screen disabled.");
}
$(window).keyup(function(e){
if(e.keyCode == 44){
copyToClipboard();
}
});
$(window).focus(function() {
$("body").show();
}).blur(function() {
$("body").hide();
});
</script>