Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check, if a HTML5 input is supported?

I want to check in my website, if the visitors browser support a HTML5 input type. How should I do it?

like image 747
Uw001 Avatar asked Nov 26 '11 13:11

Uw001


People also ask

How can I tell if HTML5 is supported?

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.

How do you check input in HTML?

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.

How does browser identify HTML5?

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.


2 Answers

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.

like image 171
Gp2mv3 Avatar answered Sep 19 '22 18:09

Gp2mv3


Modernizr has support for checking the new input types.

like image 23
pimvdb Avatar answered Sep 18 '22 18:09

pimvdb