Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect browser's native date/time pickers

For a mobile html5/js website I would like to leverage native browser date/time pickers when available (like on mobile safari for instance). I know I can detect if the browser supports the date/datetime input types, which will help ensure the proper data format is entered, but is there a proper way to detect if the current browser offers native date and/or time picker?

like image 613
Romain Avatar asked Dec 10 '25 03:12

Romain


1 Answers

you can create an input element and try to assign the type, if it's not supported the type will switch back to the default type (which is text)

function isDateSupported() {
    var i = document.createElement("input");
    i.setAttribute("type", "date");
    return i.type !== "text";
}

or you can use a tool like modernizr


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!