How would I detect if a "multiple" attribute is supported for file input elements?

Internet Explorer does not support the multiple attribute for <input type="file" /> . However, it is not only IE that lacks this support ... also some mobile browsers do not support the multiple attribute. Thus, simply detecting that the browser is IE is not an ideal solution.

So, how would I determine if the multiple attribute is supported for <input type="file" /> with JavaScript?

UPDATE

Modernizr seems to have support for the new attributes of the HTML5 input element:

http://modernizr.com/docs/#input

The accepted solution seems to work, however, since I am already using Modernizr, my solution is this:

 /** * Determines if the given attribute is supported for <input /> elements. * * @param attribute - the attribute to test for (ex. "multiple") */ function isInputAttributeSupported(attribute) { return (Modernizr.input[attribute]) ? true : false; }; 
+7
source share
2 answers
 var inp = document.createElement("input"); inp.setAttribute("multiple", "true"); var supportsMultiple = inp.multiple===true; 
+8
source

You can try to check for the corresponding property:

 var supportsMultipleFiles = 'multiple' in document.createElement('input'); 

Example: http://jsfiddle.net/sbZvS/

+13
source

All Articles