防止頁面被調試

 

實現原理


執行如下方法,會進入斷點,若是斷點的時間 >10毫秒,那麼我就認爲你正在調試。


JS代碼中執行

 1 (function noDebuger() {  2 
 3     function testDebuger() {  4         var d = new Date();  5         debugger;  6         if (new Date() - d > 10) {  7             document.body.innerHTML = '<div style="width: 100%;height: 50px;font-size: 30px;text-align: center;font-weight: bold;">年輕人,不要太好奇</div>';  8             return true;  9  } 10         return false; 11  } 12 
13     function start() { 14         while (testDebuger()) { 15  testDebuger(); 16  } 17  } 18 
19     if (!testDebuger()) { 20         window.onblur = function () { 21             setTimeout(function () { 22  start(); 23             }, 500) 24  } 25     }else { 26  start(); 27  } 28 
29 
30 })();

 

JSP頁面中執行:建議使用這種

使用的時候,能夠將js方法壓縮  http://tool.chinaz.com/js.aspxjavascript

 1 <%--禁用調試--%>
 2 <c:if test="${!debug}">
 3     <script type="text/javascript">
 4         (function noDebuger() {  5 
 6             function testDebuger() {  7                 var d = new Date();  8                 debugger;  9                 if (new Date() - d > 100) { 10                     document.body.innerHTML = '<div style="width: 100%;height: 50px;font-size: 30px;text-align: center;font-weight: bold;">年輕人,不要太好奇</div>'; 11                     return true; 12  } 13                 return false; 14  } 15 
16             function start() { 17                 while (testDebuger()) { 18  testDebuger(); 19  } 20  } 21 
22             if (!testDebuger()) { 23                 window.onblur = function () { 24                     setTimeout(function () { 25  start(); 26                     }, 500) 27  } 28             } else { 29  start(); 30  } 31 
32 
33  })(); 34     </script>
35 </c:if>

 

 

加密後執行

1 <c:if test="${!debug}">
2     <script type="text/javascript">
3         eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('(0 k(){0 1(){j d=6 7();i;9(6 7()-d>8){l.h.b=\'<3 c="a: 8%;f: e;5-o: y;x-w: z;5-A: v;">r,q</3>\';4 u}4 t}0 2(){s(1()){1()}}9(!1()){p.B=0(){g(0(){2()},m)}}n{2()}})();',38,38,'function|testDebuger|start|div|return|font|new|Date|100|if|width|innerHTML|style||50px|height|setTimeout|body|debugger|var|noDebuger|document|500|else|size|window|不要太好奇|年輕人|while|false|true|bold|align|text|30px|center|weight|onblur'.split('|'),0,{}))
4     </script>
5 </c:if>
相關文章
相關標籤/搜索