js禁止鼠标右键及F12禁止查看源代码及禁止其他操作-Discuz教程下载

js禁止鼠标右键及F12禁止查看源代码及禁止其他操作

开通本站Svip会员,全站资源免费下
1. 禁用F12
  1. <script>
  2.     document.onkeydown = function (e) {

  3.     var currKey = 0, evt = e || window.event;

  4.     currKey = evt.keyCode || evt.which || evt.charCode;

  5.     if (currKey == 123) {

  6.         window.event.cancelBubble = true;

  7.         window.event.returnValue = false;

  8.     }

  9. }
  10. </script>
复制代码
2.禁用鼠标右键
  1. <script>
  2.     document.oncontextmenu = function (event) {

  3.     if (window.event) {

  4.         event = window.event;

  5.     }

  6.     try {

  7.         var the = event.srcElement;

  8.         if (!((the.TAGName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {

  9.             return false;

  10.         }

  11.         return true;

  12.     } catch (e) {

  13.         return false;

  14.     }

  15. }
  16. </script>
复制代码
3.禁止复制
  1. <script>
  2.     document.oncopy = function (event) {
  3.         if (window.event) {
  4.             event = window.event;
  5.         }
  6.         try {
  7.             var the = event.srcElement;
  8.             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9.                 return false;
  10.             }
  11.             return true;
  12.         } catch (e) {
  13.             return false;
  14.         }
  15.     }
  16. </script>
复制代码
4.禁止剪切
  1. <script>
  2.     document.oncut = function (event) {
  3.         if (window.event) {
  4.             event = window.event;
  5.         }
  6.         try {
  7.             var the = event.srcElement;
  8.             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9.                 return false;
  10.             }
  11.             return true;
  12.         } catch (e) {
  13.             return false;
  14.         }
  15.     }
  16. </script>
复制代码
禁止选中
  1. <script>
  2.     document.onselectstart = function (event) {
  3.         if (window.event) {
  4.             event = window.event;
  5.         }
  6.         try {
  7.             var the = event.srcElement;
  8.             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9.                 return false;
  10.             }
  11.             return true;
  12.         } catch (e) {
  13.             return false;
  14.         }
  15.     }
  16. </script>
复制代码
有效禁止F12和右击(单击浏览器设置里 开发者-审查元素 无法禁止)
  1. <script>
  2. //屏蔽F12和右键
  3. function click(e) {
  4. if (document.all) {
  5. if (event.button == 2 || event.button == 3) {
  6. alert("欢迎光临寒舍,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!");
  7.           oncontextmenu = 'return false';
  8.         }
  9.       }
  10. if (document.layers) {
  11. if (e.which == 3) {
  12.           oncontextmenu = 'return false';
  13.         }
  14.       }
  15.     }
  16. if (document.layers) {
  17.       document.captureEvents(Event.MOUSEDOWN);
  18.     }
  19.     document.onmousedown = click;
  20.     document.oncontextmenu = new Function("return false;")

  21.     document.onkeydown = document.onkeyup = document.onkeypress = function () {
  22. if (window.event.keyCode == 123) {
  23.         window.event.returnValue = false;
  24. return (false);
  25.       }
  26.     }
复制代码
有效禁止F12和右击、审查元素----设置中强行打开开发者会直接关闭网页。
该方法在demo阶段发现两个问题:
1,方法会导致手机端无法滑动,滑动或者操作会被判定为改变分辨率造成强制关闭网页的情况。
2,在别的页面打开F12在加载自己的网页时,虽然也及时关闭,但在响应里还是可以看到流量包。
  1. <script>
  2. //禁用右键(防止右键查看源代码)
  3.     window.oncontextmenu = function () { return false; }
  4. //禁止任何键盘敲击事件(防止F12和shift+ctrl+i调起开发者工具
  5.     window.onkeydown = window.onkeyup = window.onkeypress = function () {
  6.       window.event.returnValue = false;
  7. return false;
  8.     }
  9. //如果用户在工具栏调起开发者工具,那么判断浏览器的可视高度和可视宽度是否有改变,如有改变则关闭本页面
  10. var h = window.innerHeight, w = window.innerWidth;
  11.     window.onresize = function () {
  12. if (h != window.innerHeight || w != window.innerWidth) {
  13.         window.close();
  14.         window.location = "about:blank";
  15.       }
  16.     }
  17. </script>
复制代码
更多禁用js
  1. //禁止鼠标右击
  2.       document.oncontextmenu = function() {
  3.         event.returnValue = false;
  4.       };
  5.       //禁用开发者工具F12
  6.       document.onkeydown = document.onkeyup = document.onkeypress = function(event) {
  7.         let e = event || window.event || arguments.callee.caller.arguments[0];
  8.         if (e && e.keyCode == 123) {
  9.           e.returnValue = false;
  10.           return false;
  11.         }
  12.       };
  13.       let userAgent = navigator.userAgent;
  14.       if (userAgent.indexOf("Firefox") > -1) {
  15.         let checkStatus;
  16.         let devtools = /./;
  17.         devtools.toString = function() {
  18.           checkStatus = "on";
  19.         };
  20.         setInterval(function() {
  21.           checkStatus = "off";
  22.           console.log(devtools);
  23.           console.log(checkStatus);
  24.           console.clear();
  25.           if (checkStatus === "on") {
  26.             let target = "";
  27.             try {
  28.               window.open("about:blank", (target = "_self"));
  29.             } catch (err) {
  30.               let a = document.createElement("button");
  31.               a.onclick = function() {
  32.                 window.open("about:blank", (target = "_self"));
  33.               };
  34.               a.click();
  35.             }
  36.           }
  37.         }, 200);
  38.       } else {
  39.         //禁用控制台
  40.         let ConsoleManager = {
  41.           onOpen: function() {
  42.             alert("Console is opened");
  43.           },
  44.           onClose: function() {
  45.             alert("Console is closed");
  46.           },
  47.           init: function() {
  48.             let self = this;
  49.             let x = document.createElement("div");
  50.             let isOpening = false,
  51.               isOpened = false;
  52.             Object.defineProperty(x, "id", {
  53.               get: function() {
  54.                 if (!isOpening) {
  55.                   self.onOpen();
  56.                   isOpening = true;
  57.                 }
  58.                 isOpened = true;
  59.                 return true;
  60.               }
  61.             });
  62.             setInterval(function() {
  63.               isOpened = false;
  64.               console.info(x);
  65.               console.clear();
  66.               if (!isOpened && isOpening) {
  67.                 self.onClose();
  68.                 isOpening = false;
  69.               }
  70.             }, 200);
  71.           }
  72.         };
  73.         ConsoleManager.onOpen = function() {
  74.           //打开控制台,跳转
  75.           let target = "";
  76.           try {
  77.             window.open("about:blank", (target = "_self"));
  78.           } catch (err) {
  79.             let a = document.createElement("button");
  80.             a.onclick = function() {
  81.               window.open("about:blank", (target = "_self"));
  82.             };
  83.             a.click();
  84.           }
  85.         };
  86.         ConsoleManager.onClose = function() {
  87.           alert("Console is closed!!!!!");
  88.         };
  89.         ConsoleManager.init();
  90.       }
复制代码

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部