Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!