接上一篇,忽然想起來,相似於網頁裏如何使用js禁用鼠標右擊事件,還有禁用F12事件也能夠禁用一下,總所周知,對於Web開發人員來講,經常要進行界面的調試。使用F12調試工具可以很方便地進行調試,查看html元素,查看響應事件。網頁裏如何使用js禁用F12事件?html
document.onkeydown=function (e){ var currKey=0,evt=e||window.event; currKey=evt.keyCode||evt.which||evt.charCode; if (currKey == 123) { window.event.cancelBubble = true; window.event.returnValue = false; } }
完整demo:前端
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>鼠標右鍵事件</title> </head> <body> <p id="tar">這裏是一些內容 <menu id="menu"> <ul> <li>王小婷</li> <li>祈澈菇涼</li> <li>安安安安</li> </ul> </menu> </p> </body> <script> /*document.oncontextmenu = function(){return false;}*/ document.onkeydown=function (e){ var currKey=0,evt=e||window.event; currKey=evt.keyCode||evt.which||evt.charCode; if (currKey == 123) { window.event.cancelBubble = true; window.event.returnValue = false; } } </script> </html>
注:編程
原文做者:祈澈姑娘技術博客:https://www.jianshu.com/u/05f416aefbe1
90後前端妹子,愛編程,愛運營,愛折騰。
堅持總結工做中遇到的技術問題,堅持記錄工做中所所思所見,歡迎你們一塊兒探討交流。工具