Herbal Supplements - Calendar news - Debt Consolidation - Online Kredit ohne Schufa - Privatkredit - Wordpress Themes

PDA

View Full Version : disable right click on images only?


disgust
Dec 4th 2006, 3:19 pm
(yes, I know users can get past this-- doesn't matter in this specific instance)

I'd like to disable right clicking on certain images, either pagewide or image-by-image. I don't want an annoying error popup, I'd just like nothing to happen at all. is that possible?

anyone have a simple script handy that'd do this?

if nothing's available I guess I'll ripoff flickr's spaceball.gif thing

lbalance
Dec 4th 2006, 3:23 pm
i use this code on some of my pages.
i put it just below the <body> tag.


<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")

// -->
</script>

disgust
Dec 4th 2006, 3:48 pm
thanks, certainly a start to what I'm after. is there any reasonably easy way to make it impact images only though?

franklinrony
Jul 5th 2009, 4:46 pm
work with ff too? i try one but after alert box,show context menu

zain654321
Jul 8th 2009, 3:40 am
<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function right(e) {
var msg = "Sorry, you don't have permission to right-click.";
if (navigator.appName == 'Netscape' && e.which == 3) {
alert(msg);
return false;
}
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
alert(msg);
return false;
}
else return true;
}

function trap()
{
if(document.images)
{
for(i=0;i<document.images.length;i++)
{
document.images[i].onmousedown = right;
document.images[i].onmouseup = right;
}
}
}
// End -->
</SCRIPT>
</HEAD>

<!-- STEP ONE: Copy the event handler into the BODY tag -->

<BODY onLoad="trap()">

<!-- Script Size: 0.81 KB -->

nirajkum
Jul 9th 2009, 1:45 am
thanks for the code