With the given code you can simply disable right click on hole of the page. However you can also disable right click on particular element.
$(document).bind('contextmenu', function (e) {
e.preventDefault();
alert('Right Click is not allowed');
});
Though disabling right click with any code not is complete solution to save the data, there are many tool to get your image or source code, but it will make task difficult for normal user.
CODE
<!DOCTYPE html> <html> <head> <title>jQuery With Example</title> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $(document).bind('contextmenu', function (e) { e.preventDefault(); alert('Right Click is not allowed'); }); /*$('.Container').bind('contextmenu',function(e){ e.preventDefault(); alert('Right Click is not allowed on div'); });*/ }); </script> </head> <body> <div class="Container" style="border:1px solid Red; width:300px;"> <p>Please right Click here for test this example</p> <input type="text" /><br> <input type="checkbox" /> </div> <button id="btnClick">Click</button> </body> </html>
DISPLAY
Please right Click here for test this example
Thnaks, this worked perfectly!!
ReplyDeleteHi,it works on all the controls other than iframes:(
ReplyDeletei am unable to find any fix for this issue. Please help!
Hi Junaid
DeleteIt is not possible if it's on an external domain. But it is possible if the page inside an iframe is on the same domain.
Please view demo on given below link
http://jsfiddle.net/nirbhaysingh/F2uVB/
If we click on Checkbox after second click then it is not working so it is not helpful to use.
ReplyDeleteHi Imtiyaz,
DeleteAfter your comment I have also include a checkbox in this example and it is working fine and you can see you are not able to right click on even checkbox.
thank u
ReplyDeletenice,worked perfectly!!!!!!!
ReplyDeleteAll of your posts are so relevant and needful ..Please provide some tutorial on dynamically fill create or load forms and also creating image dynamically on a particular events thanks.
ReplyDeleteGood
ReplyDeleteGood Example
ReplyDeleteits nice Thank you
ReplyDeleteNice Example....
ReplyDeleteThanks... :)
i want to disable right click on iframe
ReplyDeletethanks a lot ..............
ReplyDeleteI want to disable the right click on div not for whole page the syntax that you given is not working or please give me any link of example thanks
ReplyDeleteHi Rajendra,
DeleteIts working, however I am giving you a link. Please check it.
http://jsfiddle.net/nirbhaysingh/pLcam40h/
Good example,
DeleteBut why it doesn't work with me when i tried to but the codes at Dreamweaver could you attach the source code please.
Its working perfectly. Thanks a lot
ReplyDeletewell - great tutorial
ReplyDeletehow to disable right click context menu on youtube videos plese help me if any possible
ReplyDeleteHi, That's Superb Tutorial, It is very helpful knowledge, I like it, Thanks a lot for shared..........
ReplyDeleteTry this:
ReplyDelete$(document).ready(function(){
$(this).bind("contextmenu", function(e) {
e.preventDefault();
});
});
Ha tell me how to disable mouse right click popup menu on modal window
ReplyDeleteThank for alert box but is it possible to show disable message in custom popup? If yes please can you provide me demo link.
ReplyDeleteinteresting writing, no doubt i learn lots by this tutorial
ReplyDeletePerfect tip thanks :)
ReplyDeleteanother question
some script that closes the window by clicking right mouse ?