Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  163] [ 2]  / answers: 1 / hits: 15797  / 13 Years ago, fri, november 11, 2011, 12:00:00

I'd like to change drop zone background color to green or red depending on whether the contained drag over payload contains supported file types (JPEG).




  • Do Gecko and Webkit support determining the file type of drag and drop files?


  • How one can extract the file type in these two browsers?




I have found event.dataTransfer.types API, but for Firefox it seems to be populated with application/x-moz-file and thus I think I am doing something wrong.


More From » html

 Answers
52

You can get the file types in Gecko and webkit supported browsers using file object.



var files =e.dataTransfer.files||e.target.files; // File list


The file object returns Name,Type and size. you can get last modified date too.



var mimeType= files[0].type; //mime type of file list first entry

[#89187] Thursday, November 10, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daijab

Total Points: 60
Total Questions: 99
Total Answers: 110

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
;