以下代码工作正常,但如果我点击双 Ctrl + u ,则会打开所有代码。如何禁用所有?
Ctrl + u , Ctrl + s ,右键单击, F12 隐藏代码的密钥和更多密钥?
document.onkeydown = function(e) {
if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) { //Alt+c, Alt+v will also be disabled sadly.
alert('not allowed');
}
return false;
};
答案 0 :(得分:0)
你必须放e.stopImmediatePropagation();
/*function check(e)
{
alert(e.keyCode);
}*/
document.onkeydown = function(e) {
if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) { //Alt+c, Alt+v will also be disabled sadly.
alert('not allowed');
e.stopImmediatePropagation();
}
return false;
};
答案 1 :(得分:0)
尝试使用e.preventDefault()
功能。在这种情况下,按下组合键时,它将停止浏览器执行默认操作。
F12
按钮的关键代码为123
。要检测“contextmenu”事件(用户单击右键),还必须使用preventdefault函数来避免打开上下文菜单。也许这会对你有所帮助:
实时预览:At which point does for or for /R enumerate the directory (tree)?
document.onkeydown = function(e) {
if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117) || e.keyCode === 123) { //Alt+c, Alt+v will also be disabled sadly.
alert('not allowed');
e.preventDefault();
}
return false;
};
window.oncontextmenu = function (e)
{
alert("You have tested if your right-mousebutton is still working. This alert confirms it's still working, have a nice day!")
e.preventDefault();
return false; // cancel default menu
}
右键单击功能的来源:https://jsfiddle.net/cmLf34h3/1/
注意:你不能100%阻止这些行为,总有一个后门可以绕过这个。
我希望这会有所帮助