I have implemented drag and drop feature to my React app. but when I drag and drop image into application. it always opens new tab, but anyway the drag and drop is working well. I need only to prevent to open new tab.
Asked
Active
Viewed 1,806 times
1
-
Does this answer your question? [Prevent browser from loading a drag-and-dropped file](https://stackoverflow.com/questions/6756583/prevent-browser-from-loading-a-drag-and-dropped-file) – Thomas Potaire Jan 12 '22 at 20:11
1 Answers
3
You should add preventDefault() on all dragover and drop events handlers.
Example:
window.addEventListener("dragover",function(e){
e = e || event;
e.preventDefault(); <=================
},false);
window.addEventListener("drop",function(e){
e = e || event;
e.preventDefault(); <=================
},false);
danronmoon
- 3,682
- 5
- 33
- 56
Mayur Kukadiya
- 2,115
- 15
- 46