最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery.support to detect JavaScript's File API? - Stack Overflow

programmeradmin6浏览0评论

I can't find the way to detect if the browser supports the File API through the .support methon in jQuery.

Anyone knows it?

(Incidentally: a way to detect the size of a file in input[type=file] with IE?)

I can't find the way to detect if the browser supports the File API through the .support methon in jQuery.

Anyone knows it?

(Incidentally: a way to detect the size of a file in input[type=file] with IE?)

Share Improve this question asked Sep 9, 2011 at 11:39 Naoise GoldenNaoise Golden 8,9134 gold badges51 silver badges66 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 11

It does not seem to be implementd in jQuery, but you could check yourself: http://jsfiddle.net/pimvdb/RCz3s/.

The files property of an <input type='file'> returns an empty FileList if it's implemented, and otherwise it is not defined (i.e. it is 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
})();

Another way to check is just by checking the presence of the File API types:

var FileApiSupported = !!('File' in window &&
                          'FileReader' in window &&
                          'FileList' in window &&
                          'Blob' in window);
发布评论

评论列表(0)

  1. 暂无评论