我找不到通过jQuery 中的方法来检测浏览器是否支持File API的方法。.support
有人知道吗?
(顺便说一句:input[type=file]
用 IE 检测文件大小的方法?)
它似乎没有在 jQuery 中实现,但您可以检查自己:http: //jsfiddle.net/pimvdb/RCz3s/。
如果实现了 an的files
属性,则<input type='file'>
返回空FileList
,否则未定义(即它是undefined
)。
var support = (function(undefined) {
return $("<input type='file'>") // create test element
.get(0) // get native element
.files !== undefined; // check whether files property is not undefined
})();
另一种检查方法是检查File API类型的存在:
var FileApiSupported = !!('File' in window &&
'FileReader' in window &&
'FileList' in window &&
'Blob' in window);