Hola,
¿Como podría desactivar el click derecho cuando se le está haciendo a una imagen? Es que quiero que a los usuarios se les resulte más difícil descargar imágenes desde mi aplicación web. (Entiendo que evitar al 100% es imposible, pero de todas formas para limitar al usuario común MESSIrve :xD)
Estuve viendo varios temas pero siempre es lo mismo, te terminan diciendo como desactivar el click derecho a nivel general cuando yo solamente quiero desactivarlo cuando se le hace click derecho a una imágen.
¿Alguna idea?
Gracias.
Buenas, la funcion que tienes que usar es preventDefault()
CitarIf this method is called, the default action of the event will not be triggered.
En el addlistener() o en on(), depende de si usas javascript o Jquery, debes de poner evento tipo
contextmenu
<!DOCTYPE html>
<html>
<body>
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" id="image">
<script>
document.getElementById("image").addEventListener("contextmenu", function(event){
event.preventDefault()
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" id="image">
<script>
$(document).ready(function(){
$("#image").on("contextmenu",function(event){
event.preventDefault();
})
})
</script>
</body>
</html>
DOC: https://developer.mozilla.org/es/docs/Web/API/Event/preventDefault
DEMO: https://www.w3schools.com/code/tryit.asp?filename=GIRN368E2XM7
Enlace de interés: Como evitar mostrar el inspeccionador de elementos:https://es.stackoverflow.com/questions/50436/ocultar-c%C3%B3digo-html5-php-de-una-web
¡Muchas gracias, me sirvió perfecto!