如何检测浏览器目录选择能力?(How to detect directory select capa

2019-09-21 20:43发布

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?

Answer 1:

也许这是你的问题的解决方案:

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


文章来源: How to detect directory select capability in browsers?