(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
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> Code (markup):
thanks, certainly a start to what I'm after. is there any reasonably easy way to make it impact images only though?
<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.onmousedown = right; document.images.onmouseup = right; } } } // End --> </SCRIPT> </HEAD> <!-- STEP ONE: Copy the event handler into the BODY tag --> <BODY onLoad="trap()"> <!-- Script Size: 0.81 KB -->