Is it possible to remove “Inspect Element”?

我的梦境 提交于 2019-11-28 07:01:45

It is possible to prevent the user from opening the context menu by right clicking like this (javascript):

document.addEventListener('contextmenu', function(e) {
  e.preventDefault();
});

By listening to the contextmenu event and preventing the default behavior which is "showing the menu", the menu won't be shown. But the user will still be able to inspect code through the console (by pressing F12 in Chrome for example).

ramakrishna

I have one requirement for one page. In that page I want to block the user to perform below actions,

  • Right Click
  • F12
  • Ctrl + Shift + I
  • Ctrl + Shift + J
  • Ctrl + Shift + C
  • Ctrl + U

For this I googled, finally got the below link,

http://andrewstutorials.blogspot.in/2014/03/disable-ways-to-open-inspect-element-in.html

I tested with Chrome browser & fire foz. It's working for my requirement.

Right Click

 `<body oncontextmenu="return false;">`

Keys

document.onkeydown = function(e) {
  if(event.keyCode == 123) {
     return false;
  }
  if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
     return false;
  }
  if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
     return false;
  }
  if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
     return false;
  }
  if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
     return false;
  }
}

Nope. Closest you can do is capture right clicks, and make them not open the context menu, but the savvy user will know the keyboard combos or menu options to access it anyway, defeating the point. That's a feature of the browser, so nothing you do in your page is going to defeat it (short of installing malware on their computer).

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(event)
{
  if(event.button==2)
   {
     alert(status);
     return false;    
   }
}
</script>

While not an answer, Chrome certainly has a way to do this, I appear to be in an A/B test as my work account can't inspect in Gmail, meanwhile my personal account can.

I've searched for <meta> tags or HTTP headers which might be controlling this, but nothing stands out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!