Prevent right click of mouse and block F12 key, Ctrl+Shift+I of keyboard on webpage using jquery function

In jquery there is differect types of events in which we have to block 'F12','Ctrl+Shift+I' and right click i.e.'keycode 123' for whole document. All keycode and button  opens the Inspect Element screen in the browser. Adding a keydown event than only does return false for 123 will block the Inspect Element screen.

For preventing Right click Context menu:
 
$(document).on("contextmenu", function (e) {        
    e.preventDefault();
});

For preventing 'F12' and 'Ctrl+Shift+I' button click:
 
$(document).keydown(function (event) {
    if (event.keyCode == 123) // Prevent F12
    { 
        return false;
    } 
    else if(event.ctrlKey && event.shiftKey && event.keyCode == 73)
    // Prevent Ctrl+Shift+I
    {         
        return false;
    }
});
 

For more details you can ask in the comments for more queries ...

No comments:

Post a comment

If you have any doubts regarding the post. Please let me know.