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

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

Post a Comment

Popular posts from this blog

Jquery 'On' (Events,Direct ,Delegated)

jquery attr() vs prop() (difference)

jQuery popup (dialog) form validation on a normal button click