Is it possible to remove “Inspect Element”?

后端 未结 9 1067
予麋鹿
予麋鹿 2020-12-05 01:10

Is it possible to remove or disable \"Inspect Element\" context menu in Chrome App via Javascript?

I have searched through several forums but there are no definite a

相关标签:
9条回答
  • 2020-12-05 01:36

    In case it helps anyone, Inspect Element can be disabled for an individual element by adding the style pointer-events: none; to it.

    This is very useful if you have any elements that are purely for the purpose of aligning child elements that necessarily overlap a large area of more useful elements; it lets you prevent the aligner elements from responding to the Inspect Element command.

    0 讨论(0)
  • 2020-12-05 01:37

    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).

    0 讨论(0)
  • 2020-12-05 01:39

    You can't.

    Everything on a web page is rendered by the browser, and they want web sites to properly work on them or their users would despise them. As a result, browsers want to expose the lower level ticks of everything to the web developers with tools like code inspectors.

    You could try to prevent the user from entering the menu with a key event. Something like this:

    // Disable inspect element
    $(document).bind("contextmenu",function(e) {
      e.preventDefault();
    });
    $(document).keydown(function(e){
      if(e.which === 123){
        return false;
    }
    });
    

    But if a user want to see the code, he will do it in another way. He will just need a little longer.

    Short: If you do not want people to get something in their browser, you shouldn't send it to their browser in the first place.

    0 讨论(0)
  • 2020-12-05 01:42

    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 it with Chrome & Firefox. 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;
      }
    }
    
    0 讨论(0)
  • 2020-12-05 01:43
    <script language="javascript">
    document.onmousedown=disableclick;
    status="Right Click Disabled";
    function disableclick(event)
    {
      if(event.button==2)
       {
         alert(status);
         return false;    
       }
    }
    </script>
    
    0 讨论(0)
  • 2020-12-05 01:44

    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

    0 讨论(0)
提交回复
热议问题