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 answer.
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).
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>
来源:https://stackoverflow.com/questions/28690564/is-it-possible-to-remove-inspect-element