Enhancing Webpage Security with jQuery: Preventing Right-Click and Hotkey Access

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;
    }
});
 

Related Articles:
1. Check current date falls between two dates function in jquery
2. Loading gif image for freeze page to process ajax request in jquery

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.