cdmafra Posted September 18, 2013 Share Posted September 18, 2013 Hello. I'm having troubles disabling right click on images. The website shows the message that is supposed to be shown when I perform the right click, but also shows the right click menu (copy, save image as, etc.). What is the problem with this code (I'm not pasting the tags, only the "body" of the code)? var clickmessage="Clique com o botão direito desactivado nas imagens!" 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.onmousedown=disableclick; } if (document.all) document.onmousedown=disableclick else if (document.getElementById) document.onmouseup=disableclick else if (document.layers) associateimages() Quote Link to comment https://forums.phpfreaks.com/topic/282230-disable-right-click/ Share on other sites More sharing options...
trq Posted September 18, 2013 Share Posted September 18, 2013 Why are you even attempting to do this? It does nothing but annoy users. Quote Link to comment https://forums.phpfreaks.com/topic/282230-disable-right-click/#findComment-1449960 Share on other sites More sharing options...
cdmafra Posted September 18, 2013 Author Share Posted September 18, 2013 Why are you even attempting to do this? It does nothing but annoy users. I need to do, it's a exigence of some media pics databases websites... only for images of course Quote Link to comment https://forums.phpfreaks.com/topic/282230-disable-right-click/#findComment-1449967 Share on other sites More sharing options...
trq Posted September 18, 2013 Share Posted September 18, 2013 I need to do Why, what do you hope to achieve by doing so? Quote Link to comment https://forums.phpfreaks.com/topic/282230-disable-right-click/#findComment-1449977 Share on other sites More sharing options...
Psycho Posted September 18, 2013 Share Posted September 18, 2013 What trq is getting at is that whatever you think you are preventing - you aren't. It is very, very simple to override any JavaScript tricks you may put in. I assume you are trying to prevent users from copying the images. You do realize that as soon as a user sees the image in your page that the image is already downloaded to their PC, right? Also, users can easily disable JavaScript. And there are utilities that will automatically copy images from web pages for you. And, if all else fails, the user can take a screenshot of their screen and crop the picture out. Using JavaScript is a huge waste of time and, as trq stated, it only annoys users. If the user happened to be over an image when they need that context menu (e.g. print) they would be frustrated. The one simple trick I've seen that I would advise, is to put a transparent gif over the image. Then, when the user tries to copy the image, they will just get the gif. Of course, once the user realizes this, they can easily get the real image using any of the previously stated methods above. If you want to put your images on the net - then you have to assume people will copy them. The only thing you can really do is put a watermark on the images to prevent people from passing off the images as their own. Quote Link to comment https://forums.phpfreaks.com/topic/282230-disable-right-click/#findComment-1449995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.