1,禁用F12,阻止默认行为调试
window.onkeydown=window.onkeyup=window.onkeypress=function(event){io
if(event.keyCode==123){event
event.prevnentDefault()function
window.event.returnValue=false;快捷键
}co
}return
2,禁用右键context
window.oncontextmenu=function(event){location
event.preventDefault();
return false;
}
3,禁用预先调试
除了打开F12,右键,用户还有可能先打开任意网页的F12,而后在地址栏输入网址,或者使用快捷键ctrl+shift+i打开控制台
因此对于这两种状况,咱们能够经过 比较屏幕window.outerWidth和页面可见区域window.innerWidth的差距判断是否打开控制台;
var threshold=160;
setInterval(function(){
if(window.outerWidth-window.innerWidth>threshold || window.outerHeight-window.innerHeight>threshold){
//打开控制台就刷新页面;
window.location.reload()
}
})