I am writing an application that's supposed to support HTML5 drag/drop API for file, much like the on described here. I would like to perform a programmatic check on whether the browser support this kind of madness :) A solution that works for now is checking whether the browser provides a FileReader class, like this:
if (typeof(FileReader) == "undefined") { $("#dropbox").hide(); } else { // connect events $("#filebox").hide(); }
But it is obviously not a correct one (I don't use that class at all).
Any ideas?
Checking for the existence of FileReader is the correct way to go about this. FileReader is an official part of the File Api. I would combine this with Modernizr. Drag and Drop support is slated for release 1.2. You should be able to grab the source on GitHub and start working with this now. http://github.com/Modernizr/Modernizr/blob/master/modernizr.js
if (!!FileReader && Modernizr.draganddrop) { // sexy drag and drop action } else { // no drag and drop support available :( }
If you haven't seen Dive into HTML5, you should definitely check out Mark Pilgrim's suggestions on detecting HTML5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With