가끔 개발자 도구를 차단하는 사이트가 존재하는데
<script>
!function() {
function detectDevTool(allow) {
if(isNaN(+allow)) allow = 100;
var start = +new Date();
debugger;
var end = +new Date();
if(isNaN(start) || isNaN(end) || end - start > allow) {
// 개발자 도구가 open 된것을 감지했을때 실행할 코드 삽입
}
}
if(window.attachEvent) {
if (document.readyState === "complete" || document.readyState === "interactive") {
detectDevTool();
window.attachEvent('onresize', detectDevTool);
window.attachEvent('onmousemove', detectDevTool);
window.attachEvent('onfocus', detectDevTool);
window.attachEvent('onblur', detectDevTool);
} else {
setTimeout(argument.callee, 0);
}
} else {
window.addEventListener('load', detectDevTool);
window.addEventListener('resize', detectDevTool);
window.addEventListener('mousemove', detectDevTool);
window.addEventListener('focus', detectDevTool);
window.addEventListener('blur', detectDevTool);
}
}();
</script>
위와 같은 방법으로 대부분 처리를 합니다.
이 경우 ctrl + shift + i 를 통해 개발자 도구를 열게되면 debugger; 가 실행되는데 그 때
allow = 9999999999;
window.removeEventListener('blur', detectDevTool);
window.removeEventListener('focus', detectDevTool);
window.removeEventListener('mousemove', detectDevTool);
window.removeEventListener('resize', detectDevTool);
window.removeEventListener('load', detectDevTool);
다음처럼 처리하면 더이상 걸리지 않게 됩니다.
728x90
'코드 기록' 카테고리의 다른 글
[flask-cors] 재설치 (0) | 2024.08.24 |
---|---|
[React] useClickOutside hook (1) | 2024.06.07 |
[Pyqt5] QMainWindow 배경 이미지 설정하기 (0) | 2024.04.14 |
Why & What (is) Spidergen ? (0) | 2024.03.30 |
Restudy Series. Javascript (2) (0) | 2024.03.30 |