Sunday, April 28, 2013

Disable right click with jquery

jQuery makes it easy to disable the right click with just few lines of codes. bind contextmenu to the document and return false. however, this will disable the right click on entire document.
$(function(){ //document.ready function
   $(document).on("contextmenu",function(e){
        alert('right click disabled');
        return false;
    });
});
to disable right click in certain elements, you can give it a class/id and use respective selector.
Example
right click disable right click
right click no right click
try it in fiddle

2 comments:

  1. Thanks the give script of disable right click is fully working for me.

    Before disable right-click you need to know its corn. It is used to navigate (go back/forward), reload and add to favorites. If you disable it, your visitors will suffer and likely avoid your blog.

    instead of this, it is better to use disable selection of text or html :

    Add the following html code to your BODY tag:
    Here is how your BODY tag may look once implemented:

    ondragstart=”return false” onselectstart=”return false”

    Checkout the demo of script on this blog: www.originbuzz.com

    Thanks

    ReplyDelete
  2. Great Article i have learned so many things from your article

    Please check this and tell me more about it:
    http://seowebsitedesigning.com/disable-mouse-right-click-using-jquery/

    ReplyDelete