How to disable or remove only Inspect element function from right click menu with help of Javascript or jQuery
I know you can completely disable right click with e.preventDefault());
document.addEventListener('contextmenu', e => e.preventDefault());
And i want Right Click menu works with all options except inspect element, it disable only inspect element function in right click menu.
like it find the word *inspect*
in menu option and disable that option which contain word *inspect*
is that any solution for this in Javascript or jQuery
2
Answers
you can loop all menu items and block them
You have limited options and none of them will really solve the problem you propose. The issue is that the inspect option is part of the browser, which is running on the users computer, that you don’t have access to. As has been stated on other SO threads before, there are numerous ways for the user to still inspect the element using the keyboard, browser main menus or even just by looking at the raw HTTP response via curl request or in tools like postman.
What you can do is prevent the user from interacting but only in a finite, narrow focused way.
This is a really simple solution that is not user friendly but if you just give the elements you don’t want inspected a
class
ordata-
attribute then you can check for this condition and prevent the inspect. However, this will disable any right-click option on that element and as you may have guessed the user will still be able to do this on another element and traverse from there: