이게 무슨 일이야!

F12, 마우스 우클릭, 복사 등 막기 본문

프론트엔드 개발

F12, 마우스 우클릭, 복사 등 막기

명동섞어찌개 2023. 1. 13. 10:54
 <script language="JavaScript">
      
       window.onload = function () {
           document.addEventListener("contextmenu", function (e) {
               e.preventDefault();
           }, false);
           document.addEventListener("keydown", function (e) {
               //document.onkeydown = function(e) {
               // "I" key
               if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
                   disabledEvent(e);
               }
               // "J" key
               if (e.ctrlKey && e.shiftKey && e.keyCode == 74) {
                   disabledEvent(e);
               }
               // "S" key + macOS
               if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
                   disabledEvent(e);
               }
               // "U" key
               if (e.ctrlKey && e.keyCode == 85) {
                   disabledEvent(e);
               }
               // "F12" key
               if (event.keyCode == 123) {
                   disabledEvent(e);
               }
           }, false);
           function disabledEvent(e) {
               if (e.stopPropagation) {
                   e.stopPropagation();
               } else if (window.event) {
                   window.event.cancelBubble = true;
               }
               e.preventDefault();
               return false;
           }
       }
//edit: removed ";" from last "}" because of javascript error
</script>
<body onkeydown="if(!event.target.matches('input')&&!event.target.matches('textarea'))return!1" oncontextmenu="return!1" onselectstart="return!1" ondragstart="return!1">

 

 

SPA 에서는 index.html  에 깔아주면 되고

리액트에서 운영 모드에서만 막고 싶으면 index.tsx 에 process.env.MODE === 'production' 조건문 안에 걸어주면 됨

 

 

참조:

https://stackoverflow.com/questions/28575722/how-can-i-block-f12-keyboard-key-in-jquery-for-all-my-pages-and-elements

 

How can I block F12 keyboard key in jquery for all my pages and elements?

I have been trying to stop inspect element to the maximum amount. I know I can't stop them but still I would really like to reduce the chance. So how do I block the F12 keyboard key in all HTML ele...

stackoverflow.com

 

'프론트엔드 개발' 카테고리의 다른 글

[Angular] Dialog 개발 - 2  (0) 2022.04.15
[Angular] Dialog 개발 - 1  (0) 2022.04.14
Comments