Jump to content

Recommended Posts

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()
Link to comment
https://forums.phpfreaks.com/topic/282230-disable-right-click/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/282230-disable-right-click/#findComment-1449995
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.