I want to check in my website, if the visitors browser support a HTML5 input type. How should I do it?
The getContext method is checked by accessing it on the created input object. The result of this expression is checked with an if-statement. If the result is true, it means that HTML5 is supported by the browser.
The checked attribute is a boolean attribute. When present, it specifies that an <input> element should be pre-selected (checked) when the page loads. The checked attribute can be used with <input type="checkbox"> and <input type="radio"> . The checked attribute can also be set after the page load, with a JavaScript.
The simple answer is that browsers don't detect HTML5 as distinct from other versions of HTML. They don't know and they don't care. Just the same as they don't know or care which version of JavaScript or level of CSS is being used.
With the form fields you can use this:
var i = document.createElement("input");
i.setAttribute("type", "color");
return i.type !== "text";
If color is supported, i.type will be color but if it's not supported, the navigator returns text as default. So a simple verification like this can help you.
Modernizr has support for checking the new input types.
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