Question

I am trying to disable right click on images using jquery. I have searched and found:

$('img').bind('contextmenu', function(e){
    return false;
}); 

but this doesnt work.

However, I tried:

$('document').bind('contextmenu', function(e){
    return false;
}); 

Which does work, but disables right click on everything.

I then tried $('document img') but this does not work either.

Is this no longer possible with new browsers? Does anyone know of a different way to do this?

(PS, running JQuery 1.10.2)

Was it helpful?

Solution

You can keep the function on the document, and check the event.target to see what element initiated the event.

I don't recommend disabling this, for this is annoying and really easy to by pass.

OTHER TIPS

For the academics of it:

$('#someElement').mousedown(function(event) {
  switch (event.which) {
      case 3:
          event.preventDefault();
          break;
}
});

As Itay said, this is annoying and can be easily worked around. I've done it (working around it) many a time, but it can be useful for certain things like custom menus.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top