Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 3: Forms > Backwards compatibility with legacy browsers - Pg. 99

cHApT E R 3 : F oRMS : BAck wA R d S co M pATIBI L ITY w ITH L E gAcY BR ow SE R S 99 Backwards compatibility with legacy browsers The big question is: What can we do for legacy browsers? The answer is that you don't retire your pre-existing JavaScript vali- dation or fancy DHTML datepickers just yet, but you leave them as a fallback after doing some feature detection. As we've seen before, browsers will fall back to using input type=text whenever they encounter a type that they don't sup- port. So, a legacy browser, faced with input type=email, will sim- ply change it to an input type=text. This change also happens in the DOM and, by checking the type of the input, we can pro- grammatically determine if the browser supports the new fancy elements, and act accordingly if not. For instance, to detect whether <input type=email> is supported, you can make a new <input type=email> with JavaScript, but don't add it to the page. Then, interrogate your new element to