Snippet O’ the Week: Disable Right-Click Completely with jQuery

August 24th, 2011  |  by  |  Published in Design, Development, Snippet O' the Week  |  9 Comments

right-click

This is a snippet I’ve been looking for for a very long time now but have never found a legit solution. Some script functions do a warning pop up or only partially disable right-click, but this little snippet completely disables it. To disable right-click is really great if you are trying to protect photos from getting stolen or things like that and I know a lot of designers and developers hate when a web site takes control over basic browser functions. But privacy is becoming a huge deal on the internet and in some case its important to protect yourself, your images and your designs from being blatantly stolen right off your digital property.

Here’s the snippet, sweet and simple – oh, don’t forget to include jQuery: (big thanks to Codrops.com for this fantastic snippet)

<script>
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
</script>

About the author

Patrick Cox wrote 37 articles on this blog.

Patrick Cox is a UI Developer at The Active Network, freelance web designer and creator of BlurbHerd.com - yet another web design blog. He's also a musician, football fanatic and pizza lover. Follow him on twitter @pcridesagain.

9 Responses to Snippet O’ the Week: Disable Right-Click Completely with jQuery

  1. SarahNo Gravatar says:

    August 28th, 2011at 8:27 pm(#)

    Thanks for the snippet. I seldom run scripts that prevent browser behavior but I did have a client ask for this in the past and I was never able to pull it off. But this works great.

  2. BBNo Gravatar says:

    September 3rd, 2011at 7:39 am(#)

    Very nice! I adapted it to disable right-click on images only (so visitors can still open links in new tabs and copy text):

    $(‘img’).ready(function(){
    $(‘img’).bind(“contextmenu”,function(e){
    return false;
    });
    });

    Thanks for the code!

  3. BBNo Gravatar says:

    September 3rd, 2011at 7:42 am(#)

    Oh shoot, let’s try that again shall we:

    {script type=”text/javascript”}
    $(‘img’).ready(function(){
    $(‘img’).bind(“contextmenu”,function(e){
    return false;
    });
    });
    {/script}

    (replace braces with inequality signs or look here http://www.webdeveloper.com/forum/showthread.php?&t=249801&is_resolved=1)

  4. Patrick CoxNo Gravatar says:

    September 3rd, 2011at 9:35 am(#)

    Sweet, that is awesome thanks! I like that better.

  5. BBNo Gravatar says:

    September 3rd, 2011at 11:58 am(#)

    You’re welcome. Thank you for the snippet, been looking for a valid JS doing this for a while :)

  6. MatNo Gravatar says:

    September 26th, 2011at 3:29 pm(#)

    Useless…
    All The user has to do is to turn off js.
    So… It protects nothing and bothers everyone.
    Nice job !

    Btw, The web is OPEN, it is a place to SHARE. If you Wang to enforce your copyright on pictures, there are plenty solutions like watermarking or going full-flash.

  7. Rommel Castro A.No Gravatar says:

    October 5th, 2011at 3:33 pm(#)

    or use

    $(document).ready(function(){
    $(this).bind(“contextmenu”,function(e){
    return false;
    });
    });

  8. nfc212No Gravatar says:

    November 20th, 2011at 7:27 am(#)

    Doesn’t work in FF8

  9. nfc212No Gravatar says:

    November 20th, 2011at 7:29 am(#)

    Even in older versions it only takes three mouse clicks to disable it.

    Another pointless script.

Leave a Response

This site is using OpenAvatar based on