前言 下午帮客户分析某文学登陆业务中,发现有页面禁用了网页右键,非常影响调试,平时遇到这种情况通常都是JS即可,但是网上查阅了资料后发现用控制台调节更灵活一些,毕竟禁用 JS 可能出现一些错位现象,于是就有了下文。 实现禁止操作 既然我们要解除就要先看看禁止效果是如何失效的,以下代码放入网站JS里面引用即可实现效果。 // 禁止右键菜单 document.oncontextmenu = function(){ return false; }; document.oncontextmenu= new Function("event.returnValue=false"); // 禁止文字选择 document.onselectstart = function(){ return false; }; document.onselectstart = new Function("event.returnValue=false"); // 禁止复制 document.oncopy = function(){ return false; }; document.oncopy = new Function("event.returnValue=false"); // 禁止剪切 document.oncut = function(){ return false; }; document.oncopy = new Function("event.returnValue=false"); // 禁止粘贴 document.onpaste = function(){ return false; }; document.onpaste = new Function("event.returnValue=false"); // 禁止F12 document.onkeydown = function () { if (window.event && window.event.keyCode == 123) { event.keyCode = 0; event.returnValue = true; return true; } }; 解除禁止操作 通常直接按F12,如果此键被禁止可以通过SHIFT + CTRL + I打开,或者通过浏览器菜单里面的“开发人员工具”。 选择控制台,输入以下代码回车即可。 // 开启右键菜单 document.oncontextmenu = function(){ return true; }; // 开启文字选择 document.onselectstart = function(){ return true; }; // 开启复制 document.oncopy = function(){ return true; }; // 开启剪切 document.oncut = function(){ return true; }; // 开启粘贴 document.onpaste = function(){ return true; }; // 开启F12键 document.onkeydown = function () { if (window.event && window.event.keyCode == 123) { event.keyCode = 0; event.returnValue = true; return true; } }; 结语 细心的朋友可能发现F12 键盘的代码中含有123,其实这个是键盘的键盘码,同理可以换成其他按键(键盘码)进行禁止某键或者开启某个按键,最后附上一份键盘码便于使用。 键盘码列表 按键名(key) 按键码(keyCode) Escape【退出键】 27 F1 112 F2 113 F3 114 F4 115 F5 116 F6 117 F7 118 F8 119 F9 120 F10 121 F11 122 F12 123 ScrollLock【滚动锁定键】 145 Print【打印键,亦可截取整个屏幕,在画图、doc、ppt等粘贴】 42 Pause【暂停键】 19 `【反引号】 192 ~【波浪号】 192 ! 49 @【艾特符,小老鼠,圈a,蜗牛】 50 #【井号】 51 $【美元符,中文状态下是人民币符】 52 % 53 ^【 折音符】 54 &【and符,和,且】 55 *【星号】 56 ( 57 ) 48 -【减号,横杆】 173 + 61 1 49 2 50 3 51 4 52 5 53 6 54 7 55 8 56 9 57 0 48 _【下划线】 173 = 61 Backspace【← 回退键】 8 Tab【制表键】 9 CapsLock【⇪字母大写锁】 20 Shift【⇧上档转换键或上档键】 16 q 81 w 87 e 69 r 82 t 84 y 89 u 85 i 73 o 79 p 80 [ 219 ] 221 Q 81 W 87 E 69 R 82 T 84 Y 89 U 85 I 73 O 79 P 80 { 219 } 221 a 65 s 83 d 68 f 70 g 71 h 72 j 74 k 75 l 76 ;【分号】 59 '【单引号】 222 \【反斜杠】 220 A 65 S 83 D 68 F 70 G 71 H 72 J 74 K 75 L 76 :【冒号】 59 "【双引号】 222 |【竖杠】 220 z 90 x 88 c 67 v 86 b 66 n 78 m 77 ,【逗号】 188 .【句号】 190 /【斜杠】 191 Z 90 X 88 C 67 V 86 B 66 N 78 M 77 <【小于号】 188 >【大于号】 190 ? 191 Control【控制键】 17 OS【window键】 91 Alt【换挡键】 18 【空格键】 32 ContextMenu【上下文菜单键,等价于鼠标右键】 93 Enter【↩回车键】 13 Insert【插入键】 45 Delete【删除键】 46 Home【起始键】 36 End【结束建】 35 PageUp【上页键】 33 PageDown【下页键】 34 ArrowUp【↑上移键】 38 ArrowRight【→右移键】 39 ArrowDown【↓下移键】 40 ArrowLeft【←左移键】 37 以下是小键盘部分 NumLock【数字锁定键】 144 / 111 * 106 - 109 + 107 Enter 13 0 96 .【点】 110 1 97 2 98 3 99 4 100 5 101 6 102 7 103 8 104 9 105 版权声明:本文为原创文章,版权归 Mark's Blog 所有,转载请注明出处!本文链接:https://www.quchao.net/WEB-Disable.html 友情提示:如果博客部分链接出现404,请留言或者联系博主修复。 WMI Scripting HTML 当前访问者IP地址及地址归属: Last modification:December 23rd, 2020 at 02:09 am © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments Next Previous Leave a Comment Cancel reply Comment * 私密评论 Name * Email * Site Leave a Comment submitting...