开发者

jquery.support to detect JavaScript's File API?

开发者 https://www.devze.com 2023-04-03 22:49 出处:网络
I can\'t find the way to detect if the browser supports the File API through the .support methon in jQuery.

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 de开发者_如何转开发tect the size of a file in input[type=file] with IE?)


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

精彩评论

暂无评论...
验证码 换一张
取 消