mvbl fst
mvbl fst

Reputation: 5263

How to detect directory select capability in browsers?

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?

Upvotes: 7

Views: 5640

Answers (2)

Dustin Wyatt
Dustin Wyatt

Reputation: 4244

'webkitdirectory' in HTMLInputElement.prototype

I think this is sufficient in modern browsers.

Upvotes: 0

twalthr
twalthr

Reputation: 2644

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;
}

Upvotes: 13

Related Questions