Wednesday, October 16, 2013

Disable Inspect Element/Source Viewing by mouse click in a website

What if you want to disable source viewing in your site? Disable the right click method? Read on to find out how.
Having inspect element in Google chrome hastens debugging process of website. We will just hover over an element and wallah! We can get the css or the technique on how that element was designed. You can also delete that element on that page. Take for instance, removing those annoying popups or changing the opacity of modal boxes. It has its benefits for debugging. But what if, we want it the other way around. What if we want to make it harder for our knowledgeable users to just delete the element. Well, it's pretty simple. The code below will disable inspect element in your website.

$(document).bind("contextmenu",function(e) {
     e.preventDefault();
});


Pretty neat right! Of course, it has it's downfall. If javascript is disabled, you can't use that. But then again, who disables their javascript nowadays? And if he does disable javascript, you probably should have a backup of noscript js. Well, that's another topic to discuss.

30 comments:

  1. It works! BUT.. f12 and menu > more tools > tools are still working. How to disable all of it?

    ReplyDelete
    Replies
    1. You need to use a reg file download or modify the local group policy editor.

      http://www.sevenforums.com/tutorials/152554-internet-explorer-f12-developer-tools-enable-disable.html

      Delete
    2. Hello, Datepicker is properly work in chrome and mozila but in Internet Explorer when i do inspect element then i can change date.
      How to solved this issues ?

      Thanks,
      Pratik

      Delete
    3. Visit our website and get top Relationship advice also Marriage tips.

      https://www.pyarmeindia.com

      Delete
  2. it`s working ... but when i press control+shift+i , i can see the page soures..

    ReplyDelete
  3. Kumar g use below code

    $(document).keydown(function(event){
    if(event.keyCode==123){
    return false;//Prevent from F12
    }
    else if(event.ctrlKey && event.shiftKey && event.keyCode==73){
    return false; //Prevent from ctrl+shift+i
    }
    });

    ReplyDelete
    Replies
    1. I tried to use the code but it says that The entity name must immediately follow the '&' in the entity reference so I am a bit confused.....

      Delete
  4. may i know where to put this code.. sorry im new with website

    ReplyDelete
  5. https://codeinaspdotnet.blogspot.com/2017/07/disable-right-click-inspect-element-and.html

    proper example to hide inspect element, short cut keys and view page source

    ReplyDelete

  6. i disabled ctrl+alt+c, f12, right click but inspect element can be open by open from any other page and then open my page or press f12 on title bar.

    ReplyDelete
  7. ¼script¾alert(¢XSS¢)¼/script¾

    ReplyDelete
  8. Nice
    Get top Blogger related tips only available

    https://www.gourabdesign.com

    ReplyDelete