Snippet O’ the Week: Disable Right-Click Completely with jQuery
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)
1 2 3 4 5 6 7 |
<script type="text/javascript">// <![CDATA[
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
// ]]></script>
|
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.
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!
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)
Sweet, that is awesome thanks! I like that better.
You’re welcome. Thank you for the snippet, been looking for a valid JS doing this for a while :)
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.
or use
$(document).ready(function(){
$(this).bind(“contextmenu”,function(e){
return false;
});
});
Doesn’t work in FF8
Even in older versions it only takes three mouse clicks to disable it.
Another pointless script.
Rommel Castro A.,
Thanks for the code snippet, that works great too.