js禁止别人查看源码

1、直接按F12

2、Ctrl+Shift+I查看

3、鼠标点击右键查看

4、Ctrl+u=view-source:+url

把以上三种状态都屏蔽掉就可以了,document有onkeydown(键盘按键事件),该事件里面找到对应的keycode并处理就可以,

document也有oncontextmenu鼠标右键事件,屏蔽即可。4里面的Ctrl+u是可以屏蔽的。
window.onload=function(){
        document.onkeydown=function(){
            var e=window.event||arguments[0];
            if(e.keyCode==123){
                alert("小样你想干嘛?");
                return false;
            }else if((e.ctrlKey)&&(e.shiftKey)&&(e.keyCode==73)){
                alert("还是不给你看。。");
                return false;
            }else if((e.ctrlKey)&&(e.keyCode==85)){//追加

        return false;
       }
        };
        document.oncontextmenu=function(){
            alert("小样不给你看");
            return false;
        }
    }

 

posted @ 2016-10-12 23:37  侠岚之弋痕夕  阅读(684)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!