Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
How disable default drag of an image?

I'm french so I'm sorry for my english. I try to do a simple drag and drop like in : https://web.dev/drag-and-drop/ but if we replace 1, 2 and 3 by a <img>, the drag and drop doesn't work because of the default dragndrop of the <img> open the file in firefox and in edge that let the image with 0.4 opacity

I try to disable this behaviour with getElementsByTagName('img').ondragstart = function(){return false;}; but that doesn't change anything I try also to put onmousedown='return false' in my img but It block the real drag and drop too

Edit: I found on the web I put in my Css :

 img{
    user-select: none;
    -moz-user-select: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

And all work in Edge not in firefox

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For this the answers are in the document you're referring to already. You need to prevent the default browser behavior using event.preventDefault(). You can put this inside a handler function e.g. function handleDrop(e) {e.preventDefault()} and then call it on drop event like - myimage.addEventListener('drop', handleDrop);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda