[whatwg] Detecting Web Forms for future proof scripts?

Hallvord R M Steen wrote:
> On 02/10/06, Ric Hardacre <ric at hardacre.org> wrote:
>>  suppose for example I wanted to emulate the
>> datalist element for a text box. I can use the DOM and some on-the fly
>> CSS to build a Javascript emulated datalist, but how would one go about
>> ensuring that if/when it encounters a browser that can handle the
>> datalist that it does not execute?
> 
> What about this attempt?
> 
> http://www.hallvord.com/opera/demo/wf2-datalist.htm

It's easier to just check for the interface.

if (window.HTMLDataListElement) {
   // datalist is supported.
}

However, thanks to a bug in Opera 9, you have do this:

if (window.HTMLDataListElement || window.HTMLDatalistElement) {
   // datalist is supported.
}

The first is what the spec defined, the second is what Opera initially 
implemented, but it's being fixed.

-- 
Lachlan Hunt
http://lachy.id.au/

Received on Monday, 2 October 2006 16:57:34 UTC