7

I am trying to find out if browser has ability to select folders, not just multiple files. Current Chrome supports this (example: http://html5-demos.appspot.com/static/html5storage/demos/upload_directory/index.html).

Apparently, it works in Chrome when <input type="file" /> has webkitdirectory attribute. But how can I test if browser is actually capable of selecting folders and iterating through files?

mvbl fst
  • 5,213
  • 8
  • 42
  • 59
  • possible duplicate of [How can I check if the browser support HTML5 file upload (FormData object)?](http://stackoverflow.com/questions/7296426/how-can-i-check-if-the-browser-support-html5-file-upload-formdata-object) – GolezTrol Aug 29 '12 at 01:06
  • It's not a duplicate. As far as I know, only Chrome supports webkitdirectory (or the future directory attribute) while other browsers currently support HTML5 File API. There is a need for such a test, as the Chrome `` allows _only_ folders to be selected, not files or folders. – Geoffrey Booth Jan 12 '13 at 00:41
  • Hey @GeoffreyBooth -- I already wrote Modernizr plugin for this. – mvbl fst Jan 12 '13 at 01:52

1 Answers1

13

Maybe this is a solution for your problem:

function isInputDirSupported() {
    var tmpInput = document.createElement('input');
    if ('webkitdirectory' in tmpInput 
        || 'mozdirectory' in tmpInput 
        || 'odirectory' in tmpInput 
        || 'msdirectory' in tmpInput 
        || 'directory' in tmpInput) return true;

    return false;
}
twalthr
  • 2,584
  • 16
  • 15