[Javascript] No right click on images
Laurent Muchacho
elmuchacho at gmail.com
Wed Sep 14 05:50:55 CDT 2005
Hi Alan,
You could try something like this
for(var i=0; i<document.getElementsByTagName('IMG').length;i++){
document.getElementsByTagName('IMG').oncontextmenu = function (){return false}
}
Laurent
----- Original Message -----
From: Alan Easton
To: javascript at LaTech.edu
Sent: Wednesday, September 14, 2005 11:38 AM
Subject: Re: [Javascript] No right click on images
Thanks Matt,
This does work, oncontextmenu="return false;"
however, the images involved are from a content management system, and the client already has hundreds all over the site.
I was hoping there could be a universal function I could paste into the HEAD of the page, and it would effect all images, instead of having to re-work all the existing images.
I have been playing with this function, which works, but it has the alert box popping up, and if I comment it out, the function does not work.
Any ideas........
//------------------code-----------------------
<script type="text/javascript">
var clickmessage="Images Copyright NC3Rs 2005"
function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}
if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()
</script>
//-----------------code-----------------------
Again, all help appreciated..........
Alan...
----------------------------------------------------------------------------
From: Matt Barton <javascript at mattbarton.org>
Reply-To: "\[JavaScript List\]" <javascript at LaTech.edu>
To: "[JavaScript List]" <javascript at LaTech.edu>
Subject: Re: [Javascript] No right click on images
Date: Wed, 14 Sep 2005 11:21:49 +0100
>Hi Alan,
>
>Pretend that at this point I'm telling you all the things that loads
>of other people are likely to say about it being a bad idea, bad
>practice, pointless if the client doesn't have javascript enabled
>etc, etc, and so on ad. nauseum.
>
>What you want is something like:
>
> <img oncontextmenu="return false;" src= ....
>
> ... or ...
>
> <img oncontextmenu="returnValue = false;" src= ....
>
>Try those, and have an experiment, I'm sure it's something like
>that.
>
>Matt
>
>Alan Easton wrote:
>>Hello All,
>> I realise this type of function is quite pointless, but a client
>>would like it.
>> I need to disable right click on images, but I DO NOT want any
>>alert box popping up, I merely do not want the right click menu to
>>appear.
>> I also need the right click to work on any other part of the
>>screen, so they can still right click and refresh, view source,
>>etc....
>> Hope I have made myself clear, let me know if you need anything
>>else from me.
>> As usual, any help would be really appreciated.
>> Alan...
>>
>>--
>>This email has been verified as Virus free
>>Virus Protection and more available at http://www.plus.net
>>
>>
>>
>>------------------------------------------------------------------------
>>
>>_______________________________________________
>>Javascript mailing list
>>Javascript at LaTech.edu
>>https://lists.LaTech.edu/mailman/listinfo/javascript
>>
>>--
>>This email has been verified as Virus free
>>Virus Protection and more available at http://www.plus.net
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
------------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050914/565900d4/attachment.htm>
More information about the Javascript
mailing list