接上一篇,突然想起来,类似于网页里如何使用js禁用鼠标右击事件,还有禁用F12事件也可以禁用一下,总所周知,对于Web开发人员来说,常常要进行界面的调试。使用F12调试工具能够很方便地进行调试,查看html元素,查看响应事件,但是对于自己开发出来的网页,我时常不想被别人看到图片,视频,源码等相关信息,于是常添加这样的代码:
document.onkeydown=function (e){
var currKey=0,evt=e||window.event;
currKey=evt.keyCode||evt.which||evt.charCode;
if (currKey == 123) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
完整demo:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鼠标右键事件</title>
</head>
<body>
<p id="tar">这里是一些内容
<menu id="menu">
<ul>
<li>王小婷</li>
<li>祈澈菇凉</li>
<li>安安安安</li>
</ul>
</menu>
</p>
</body>
<script>
/*document.oncontextmenu = function(){return false;}*/
document.onkeydown=function (e){
var currKey=0,evt=e||window.event;
currKey=evt.keyCode||evt.which||evt.charCode;
if (currKey == 123) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
</script>
</html>