5 Replies - 604 Views - Last Post: 23 August 2011 - 10:13 AM

#1 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Disabling right click on a image

Posted 18 August 2011 - 05:48 PM

I know its not one of the best ideas to disable right click on image, but my friend wants to disable it so that when a user clicks on the image to see the full version of it, the user cant right click it to save. Right now, this is the code I have, but only prevents the user from right clicking the thumbnail, I would like it for when the image is in its full version, right click is disabled.


<script language=Javascript>
<!--

var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// --> 
</script>


Is This A Good Question/Topic? 0
  • +

Replies To: Disabling right click on a image

#2 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1377
  • View blog
  • Posts: 3,501
  • Joined: 28-November 09

Re: Disabling right click on a image

Posted 18 August 2011 - 06:41 PM

Impossible and completely impractical. Anyone with any experience can download the image with no problems. Tell him to look into image obscurification instead.
Was This Post Helpful? 0
  • +
  • -

#3 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Disabling right click on a image

Posted 18 August 2011 - 07:04 PM

View PostLemur, on 18 August 2011 - 07:41 PM, said:

Impossible and completely impractical. Anyone with any experience can download the image with no problems. Tell him to look into image obscurification instead.


Yeah, anyone could still do a print screen, but I was just wondering if I could take extra measures.
Was This Post Helpful? 0
  • +
  • -

#4 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: Disabling right click on a image

Posted 18 August 2011 - 07:33 PM

yes you can disable right click on image.. using jquery is the easiest way. here's the code..

<script type="text/javascript">
$(document).ready(function(){
  $("img.fullimg").live("contextmenu",function(e){
    return false;
  });		
});
</script>



and put a class on your large image.
 <img src="something.jpg" class="fullimg">



some other code uses .bind() function to bind the contextmenu, but it's better to use .live() so that the future image will be included in the bind.

DON'T FORGET TO INCLUDE THE JQUERY LIB. ^_^

This post has been edited by LiDoNg_9_0: 18 August 2011 - 07:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1377
  • View blog
  • Posts: 3,501
  • Joined: 28-November 09

Re: Disabling right click on a image

Posted 18 August 2011 - 09:20 PM

Not the point, any skiddie can get that by disabling js. It's impossible to have a foolproof system without some extensive obscurification.
Was This Post Helpful? 0
  • +
  • -

#6 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Disabling right click on a image

Posted 23 August 2011 - 10:13 AM

View PostLiDoNg_9_0, on 18 August 2011 - 08:33 PM, said:

yes you can disable right click on image.. using jquery is the easiest way. here's the code..

<script type="text/javascript">
$(document).ready(function(){
  $("img.fullimg").live("contextmenu",function(e){
    return false;
  });		
});
</script>



and put a class on your large image.
 <img src="something.jpg" class="fullimg">



some other code uses .bind() function to bind the contextmenu, but it's better to use .live() so that the future image will be included in the bind.

DON'T FORGET TO INCLUDE THE JQUERY LIB. ^_^


Will the script work even if I have another script on my page (I have a script that tells the date on my page)? Also, how do I make the JQUERY LIB, I dont know much about JQUERY, I understand the snips of code and where they go, but no the JQUERY LIB.

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1