View Full Version : no right click script

04-19-2010, 05:26 PM
my client would like me to implement this code to disable right clicking on images... does the code look okay? And do i just place it in the header? Any help is much appreaciated

<SCRIPT language=Javascript1.2>
var message='Right Click Disabled .';
function click(e) {
if (document.all) {
if (event.button == 2) {
return false;}}
if (document.layers) {
if (e.which == 3) {
return false;}}}
if (document.layers) {
// -->

d a v e
04-19-2010, 06:32 PM
don't do it.
it annoys users makes pages less accessible and it's next to pointless.

js can easily be disabled
print screen
image taken from the cache...
waste of time for him, you and the user

04-19-2010, 06:48 PM
thanks for the reply dave. yes, im aware of how pointless and annoying disabling right clicking is, explained it to my client as well, but he still wants it done :/ i was handed this code to use, but im not very java-savvy

04-19-2010, 07:35 PM
Good grief..
The problem is that it's not only annoying for the visitors that will never come back, it's a guaranteed way to lose money.

In order to make the code work, place it in the header section of the website <head>, just make sure you don't bring along the closing </a>.


04-19-2010, 08:01 PM
thanks for the reply domedia. I placed it in the head but its not working for me. i found a similar code that works...

<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 Disabled!";

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){
else if (document.all&&!document.getElementById){

document.oncontextmenu=new Function("alert(message);return false")

// -->

..but i would like to get the original code to work for the sake of pleasing the client. not sure what the problem is :/ any more help is appreciated

oh and i did away with that </a>

04-19-2010, 08:18 PM
I would just tell your client that the code he provided did not work, but that you went to the extra length of finding one that did.
Really should be no issue. :)

04-19-2010, 08:35 PM
Yeah you're probably right, thanks for the advice!

04-20-2010, 09:29 AM
there are bucket loads of them if the client insists though


d a v e
04-20-2010, 04:18 PM
personally i would just refuse to do it ;)
or do it and then go round to their place and show them how easy it is to take the image, along with some google searches of how easy it is to find ways of doing it.

04-20-2010, 09:33 PM
hi edbr, thats how i found the dynamic drive script and it seems to be working "great".

dave, perhaps emailing them an article would have helped, but i spoke up about it twice, and its really up to them as far as im concerned.

anyway, thanks again everyone

04-20-2010, 09:36 PM
and its really up to them as far as im concerned. True, sometimes you have to be a business man and not a developer.