How to block inspect element on website

How to disable inspect element

Last Updated by Lalita 11-Mar-20

0 3090


Sometimes you want to disable inspect elements from your website to secure it. There are many ways to inspect the code of website or find the words in the code etc.

For Example: by right click, by pressing key F12, by ctrl+shift+i, by ctrl+f etc.

So to disable these keys or clicks, copy the below code and paste on your website page. Remember that it will only disable that page code where you have used this code.

<script>
/* To Disable Inspect Element */
$(document).bind("contextmenu",function(e) {
e.preventDefault();
});

$(document).keydown(function(e){
if(e.which === 123){
return false;
}
});
</script>

To disable multiple Keys used with ctrl key & ctrl+shift key

<script>
document.onkeydown = function(e) {
if(event.keyCode == 123) {
return false;
}
if(e.ctrlKey && e.keyCode == 'E'.charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.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;
}
if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.keyCode == 'H'.charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.keyCode == 'A'.charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.keyCode == 'F'.charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.keyCode == 'E'.charCodeAt(0)){
return false;
}
}
</script>

How do I disable right click on my web page


Share:


Leave a Reply


Comments
    Waiting for your comments