网页禁止右键查看源码屏蔽键盘事件

<script type="text/javascript">
      window.onload = function(){
         //屏蔽键盘事件
           document.onkeydown = function (){
               var e = window.event || arguments[0];
               //F12
                if(e.keyCode == 123){
                    return false;
              //Ctrl+Shift+I
                }else if((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)){
                   return false;
              //Shift+F10
             }else if((e.shiftKey) && (e.keyCode == 121)){
                    return false;
                //Ctrl+U
                }else if((e.ctrlKey) && (e.keyCode == 85)){
                    return false;
                }
            };
           //屏蔽鼠标右键
          document.oncontextmenu = function (){
                return false;
        }
        with(document.body) {
      oncontextmenu=function(){return false}
      ondragstart=function(){return false}
      onselectstart=function(){return false}
      onbeforecopy=function(){return false}
      onselect=function(){document.selection.empty()}
      oncopy=function(){document.selection.empty()}
    }
        }
 
 </script>
作者:赖忠标
免责声明:文章、笔记等仅供分享、探讨、参考等学习之用,因此造成的任何后果概不负责。(如有错误、疏忽等问题,欢迎指正、讨论,谢谢)
本文版权归作者和博客园共有,欢迎转载,但请务必在文章页面明显位置给出原文连接,谢谢配合。
原文地址:https://www.cnblogs.com/lazb/p/15189314.html