I'm building a mobile version of my site which has a file upload facility, accessed via an 'Upload Button'
I would like to hide the button from iPhone users, as the control just appears greyed out - is this possible?
I don't really want to detect the iPhone; I feel it would be much better to detect the feature - making it start to work automatically should Apple enable this (or the phone is Jailbroken, or something...)
We get our input element with document. getElementById() and check the length of the files property, which an input of type file has. If it's empty, we alert the user that no file has been selected.
The property value type=”file” tells that the type of input the user enters is a file. The property value id=”theFile” is used to link the JavaScript code to it using getElementById() method. The property value onclick=”initialize()” is used to specify the function call when the user has clicked on the input.
Function to check whether input[type=file]
is implemented:
function isInputTypeFileImplemented() { var elem = document.createElement("input"); elem.type = "file"; if (elem.disabled) return false; try { elem.value = "Test"; // Throws error if type=file is implemented return elem.value != "Test"; } catch(e) { return elem.type == "file"; } }
Fiddle: http://jsfiddle.net/8EqEE/9
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