Html 如何在浏览器中检测目录选择功能?

Html 如何在浏览器中检测目录选择功能?,html,file-upload,html5-filesystem,Html,File Upload,Html5 Filesystem,我试图找出浏览器是否能够选择文件夹,而不仅仅是多个文件。当前的Chrome支持这一点(例如:) 显然,当具有webkitdirectory属性时,它在Chrome中工作。但我如何测试浏览器是否真的能够选择文件夹并遍历文件?也许这是解决您问题的一个方法: function isInputDirSupported() { var tmpInput = document.createElement('input'); if ('webkitdirectory' in tmpInput

我试图找出浏览器是否能够选择文件夹,而不仅仅是多个文件。当前的Chrome支持这一点(例如:)


显然,当
具有
webkitdirectory
属性时,它在Chrome中工作。但我如何测试浏览器是否真的能够选择文件夹并遍历文件?

也许这是解决您问题的一个方法:

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

可能重复的不是重复的。据我所知,只有Chrome支持webkitdirectory(或未来的目录属性),而其他浏览器目前支持HTML5文件API。有必要进行这样的测试,因为Chrome
只允许选择文件夹,而不允许选择文件或文件夹。嘿@GeoffreyBooth——我已经为此编写了Modernizer插件。谢谢您的回答。这与我们在自定义Modernizer测试中所做的差不多。在Android Chrome中返回true,但在选择此文件后,其输入长度不会改变。