Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a browser supports <input type="time" />

Is there a way in HTML, javascript, or Razor to detect if the browser supports <input type="time" /> elements?

Thanks in advance.

like image 661
keeehlan Avatar asked Feb 17 '14 22:02

keeehlan


1 Answers

Invalid values will be rejected when assigned to the .type property of an input element.

try {
    var input = document.createElement("input");

    input.type = "time";

    if (input.type === "time") {
        console.log("supported");
    } else {
        console.log("not supported");
    }
} catch(e) {
    console.log("not supported");
}

If there's some browser issue I'm not aware of, then using .innerHTML should do the same.

var div = document.createElement("div");
div.innerHTML = "<input type='time'>";

if (div.firstChild.type === "time")
    console.log("supported");
else
    console.log("not supported");
like image 128
cookie monster Avatar answered Oct 02 '22 00:10

cookie monster