2

as you know in html5 we have got

<input type="date" name="birthday" />

but it will not supported in all browsers. I need to use it in page and if the client browsers doesn't support it,make some calender by JavaScript instead of it.

how can I understand the browsers support it or not? (I need to do it in client-side not by agent client in server side script by php)

3 Answers 3

2

Testing whether the input type=date is supported is not hard. Create a container, and set the innerHTML to <input type="date">. Then, check whether the type attribute of the element is date (unrecognised values for significant attributes are ignored).

The implementation of the previously described method is shown below. It's a stand-alone function, and doesn't require any plugins or libraries. Fiddle: http://jsfiddle.net/aWYbZ/

function isInputDateSupported(){
    var d = document.createElement("div");
    d.innerHTML = '<input type="date">'
    return d.firstChild.type == "date";
}
Sign up to request clarification or add additional context in comments.

1 Comment

+1 But why not simply create the input element? jsfiddle.net/pimvdb/aWYbZ/1
2

The Modernizr library was created to help you detect which browsers support html5 features.

Taking advantage of the new capabilities of HTML5 and CSS3 can mean sacrificing control over the experience in older browsers. Modernizr 2 is your starting point for making the best websites and applications that work exactly right no matter what browser or device your visitors use.

1 Comment

Damn, you beat me by 37 seconds.
2

The Modernizr JavaScript library does feature detection so you can easily adapt to different levels of support in different browsers. They also have links to "polyfills" which transparently port particular HTML5/CSS3 features to older browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.