Forum Moderators: open

Message Too Old, No Replies

HTML Object constructor in IE5+

         

Blackbird42

10:01 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Hi there! I'm new to the forums, so I'm sorry if this has been asked before.

I've been delving into Javascript recently after years of non-use, and I'm trying to make all my scripts W3C DOM-compatible. It doesn't really lend me any benefits, but it feels a lot nicer to code and a lot more logical. The biggest pain in getting most of my scripts to work is, of course, IE. Normally I like to make up for IE's shortcomings by writing my own transparent DOM-compatible functions in the background, and I don't want to create special functions and different execution paths for different browsers.

My way is easy for some issues (emulating Array.push for IE5, semi-emulating getElementById() for IE4 and NS4) but in order for it to work with my next problem, I need to know what the constructor and prototype is for HTML elements in IE; the new functions and variables should to be applied to all HTML elements. I know that Mozilla uses HTMLElement, but what does IE use, if anything? And does IE5 for Mac use the same constructor?

Thanks for your time!

Rambo Tribble

3:40 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE 5 Mac and IE 6 Win use HTMLElement. I'm not sure what, if anything, earlier IE's use that is comparable.

Bernard Marx

7:15 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Really? That's god news if it's true. I didn't think that IE exposes any element prototypes, or allows elements inherit from the Object prototype. IE 5 definitely doesn't.

The options all have drawbacks. You can wrap all the elements that you want to deal with; use behaviors (.htc s)); or teach Mozilla to speak IE's language (easier, but hardly very 'progressive').

WebFX [webfx.eae.net] deals with these issues,
and then there's Dean Edwards' IE 7 [dean.edwards.name] project.

Blackbird42

10:32 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



Thanks for the replies!

The only option, to fix it transparently, seems be behaviors, but I think it's just not worth it in this case. I'll simply redirect to the non-standard code when the browser doesn't support it, as much as I don't like doing so. (the case being that IE5 doesn't use attribute nodes, but rather the value itself, on element.attributes[]; it also generates an error if I try to write directly to the array)

Still, behaviors does seem to open up some possibilities if I ever get a problem big enough, so hopefully that option will be open if I ever really need it...