How to detect directory select capability in browsers?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 17:40:15

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/12169585/how-to-detect-directory-select-capability-in-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!