How to disable Right-click in a page using JQuery
When we build a website, some times we do not want the users to use the right button of the mouse on the page for some security purpose. It’s possible to either completely or partially disable the right-click of mouse or replace them with a custom dialog box which is applicable to the webpage or on complete site. The contextmenu event is sent to an element when the right button of the mouse is clicked on it, but before the context menu is displayed.
disable right-click option using the jQuery ?
You can use the following code to prevent the mouse right-click on your webpage. In this code it capture the contextmenu event when user try to click on mouse right-click button and return false in the event handler. This will block all the access to context menu from the mouse right-click.
The bind() method in this code is used to attach one or more event handlers for selected element and this method specifies a function to run when an event occurs.
$(document).bind("contextmenu",function(e) { return false; });
disable F12 using the jQuery ?
$(document).keydown(function (event) { if (event.keyCode == 123) { // disable F12 Key return false; } else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { // disable Ctrl+Shift+I Key return false; } else if (event.ctrlKey && event.keyCode == 85) { // disable Ctrl+U Key return false; } });