本方案用于网页防调试窗口,不是绝对的,但是针对不同浏览器做了不同的方案。
主要针对火狐、谷歌及谷歌内核浏览器(当然也不是绝对的方调用),能防大多数的调用调试窗口。主要通过监听
F12与Ctrl+Shift+I,网页页面大小,以及监听后台输出实现。
代码如下:
<script src="https://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).keydown(function(event){
switch(event.keyCode)
{
case 123: optProcess();
}
if(event.ctrlKey && event.shiftKey && event.keyCode==73)
{
optProcess();};
});
function optProcess(){
// 如果打开了调试窗口,则...自己发挥...
}
function isConsoleOpen(){
var element = new Image();
Object.defineProperty(element, "id", {
get: function () {
console.log("小贼!想偷代码?")
optProcess();
},
}); console.log(element);
}
var ttW=0,ttH=0,tW=0,tH=0;
var jj=false;
if(navigator.userAgent.toLowerCase().toLowerCase().indexOf("firefox")>0)
{
var threshold = 300;
setInterval(function() {
tW=window.outerWidth - window.innerWidth;
tH=window.outerHeight - window.innerHeight;
if(ttW>0 || ttH >0){
console.log(ttW,ttH)
if(ttW!=tW || ttH!=tH){
jj=true;
}
}
if ( tW > threshold || tH > threshold || jj) {
optProcess();
}
ttW=tW;
ttH=tH;
}, 1e3);
}
else if(navigator.userAgent.toLowerCase().toLowerCase().indexOf("chrome")>0)
{
setInterval(function() {
isConsoleOpen();
}, 1e3);
}
else{
var threshold = 300;
setInterval(function() {
tW=window.outerWidth - window.innerWidth;
tH=window.outerHeight - window.innerHeight;
if(ttW>0 || ttH >0){
console.log(ttW,ttH)
if(ttW!=tW || ttH!=tH){
jj=true;
}
}
if ( tW > threshold || tH > threshold || jj) {
optProcess();
}
ttW=tW;
ttH=tH;
}, 1e3);
}
</script>