Im wondering what the best way to check if the input type="field" field is available to the user?
At least iPhones and iPads does not allow the user to upload files, but rather than checking the user agent with backend code i'd like to hear what you think is the most minimalist solution?
The purpose is to check if file upoads is available, if not, set display:none; for the whole div containing the form.
Can this be done with only css? jQuery?
I'd prefer a solution which not explicitely does not check if(iOS) but rather does a more generic check.
Thank you in advance!
The most elegant way to handle this as of today is probably using Modernizr which in its latest version allows you to test for file input support with the following JS statement:
if(Modernizr.fileinput) {
//file input available!
} else {
//No file input :(
}
Alternatively if you don't wish to include Modernizr in your project there is a simple a way to test for it which only involves 3 lines of code:
var elem = document.createElement('input');
elem.type = 'file';
return !elem.disabled;
As described in this SO answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With