How to detect browser supports this HTML5 feature
-
06-06-2021 - |
質問
I want to detect (using javascript/jQuery) whether the user's browser supports multiple
attribute to input type='file'
tag. A feature of HTML5 to add multiple images.
<input type=file name="images" value=" " multiple=""/>
Please suggest me how can i do this.
解決
var i = document.createElement("input");
if (typeof i.multiple !== 'undefined') {
// supports multiple
}
他のヒント
you can use modernizr
which is developed for this purpose.
you can detect support of a feature like placeholder
in this way:
if (!Modernizr.input.placeholder) {
}
As taken & edited from the Modernizr source:
var inputElem = document.createElement('input');
var multipleSupport = !!(multiple in inputElem);
You don't need to include a complete library if this is the only thing you need.
I suggest you use Modernizr javascript library? This provides a way to check if browsers support various features.
You can use Modernizr, which does a huge number of these tests for you.
In this case, though, the test is really easy:
if (typeof document.createElement('input').multiple !== "undefined") {
// ... yes, it has it
}
The same is true of all the other new properties on elements.