By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,946 Members | 1,676 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,946 IT Pros & Developers. It's quick & easy.

Inheriting from an HTML element in IE

P: n/a

Hello,

I've recently been developping a google-maps-like api.
Firstly, I started development under Firefox, but I now need to run it
under Internet Explorer, and I'm running into a little bit of
trouble..

With firefox, a "MapView" object actually subclasses a HTMLDivElement, as
follows:

----8<----
MapView.superclass = HTMLDivElement;
MapView.prototype = document.createElement ("div");
MapView.prototype.constructor = MapView;
----8<----

but that does not work with Internet Explorer, as it does not propose
the same (W3C) DOM api as Mozilla-based browsers.

I've been looking after the type of element to subclass under IE, or a
different subclassing mechanism, but without success. Can anyone point
me some reference documentation, or propose any kind of solution?

Many thanks in advance!

Cheers,
Arnaud
Sep 6 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


aundro wrote:
MapView.superclass = HTMLDivElement;
MapView.prototype = document.createElement ("div");
MapView.prototype.constructor = MapView; but that does not work with Internet Explorer, as it does not propose
the same (W3C) DOM api as Mozilla-based browsers.
It is debatable whether the W3C DOM for its ECMAScript binding requires
an implementation to expose stuff like a HTMLDivElement constructor
function or its prototype.
In general there is not anything in the specification and the ECMAScript
binding which suggests that with a few exceptions where static stuff
like Node.ELEMENT_NODE is explicitly mentions which then obviously
requires the implementation to expose Node first to be able to expose
Node.ELEMENT_NODE.
I've been looking after the type of element to subclass under IE, or a
different subclassing mechanism, but without success. Can anyone point
me some reference documentation, or propose any kind of solution?


IE on Windows allows you to implement behaviors for elements and bind
them to elements with a CSS rule so you would encapsulate your stuff in
a behavior and bind e.g.
div { behavior: url(yourBehavior.htc); }
This is not subclassing but what you do with Mozilla is usually not
called subclassing either as ECMAScript as implemented by JavaScript 1.x
in Mozilla/Netscape or by JScript in IE does not know any classes or
class based inheritance.

As for documentation of behaviors and HTCs (HTML components) for IE:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/behaviors_node_entry.asp>
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/htcref.asp>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 6 '05 #2

P: n/a

Hi,

Martin Honnen <ma*******@yahoo.de> writes:
aundro wrote:
MapView.superclass = HTMLDivElement;
MapView.prototype = document.createElement ("div");
MapView.prototype.constructor = MapView;
but that does not work with Internet Explorer, as it does not propose
the same (W3C) DOM api as Mozilla-based browsers.


It is debatable whether the W3C DOM for its ECMAScript binding
requires an implementation to expose stuff like a HTMLDivElement
constructor function or its prototype.
In general there is not anything in the specification and the
ECMAScript binding which suggests that with a few exceptions where
static stuff like Node.ELEMENT_NODE is explicitly mentions which then
obviously requires the implementation to expose Node first to be able
to expose Node.ELEMENT_NODE.


Indeed, I shouldn't have relied on the fact that Mozilla exposes those
constructors in the first time..
I've been looking after the type of element to subclass under IE, or a
different subclassing mechanism, but without success. Can anyone point
me some reference documentation, or propose any kind of solution?
IE on Windows allows you to implement behaviors for elements and bind
them to elements with a CSS rule so you would encapsulate your stuff
in a behavior and bind e.g.
div { behavior: url(yourBehavior.htc); }


Well, the purpose of behaviors seems to be to divert the default
behavior of an element of a given type (EG: div).
What I need is to create a new type of element/object that would
'inherit' (*) all the DIV's behaviour (receive events, take the
expected screen estate, ...), but to which (to the prototype of which,
actually) I want to add some functions specific to a map API.

It seems I could do that with the HTCs, but doesn't it seem a little
overkill in this case? Maybe I could consider an alternative: make a
function for creating my MapView objects, like

---
createMapView(width, height)
---

which would just return the result of a
document.createElement("div");, to which I'd have added all the
functions specific to a map view. Something like this:

-------

// IE version
createMapView4IE(width, height) {

var d = document.createElement ("div");
d.addLayer = ___my_predefined_add_layer;
d.panNorth = ___my_predefined_pan_north;
d.panSouth = ___my_predefined_pan_south;
d.resize = ___my_predefined_resize;
...
return d;
}
-------

What do you think? Wouldn't it be simpler?
(*) I know this is not real subclassing :)
This is not subclassing but what you do with Mozilla is usually not
called subclassing either as ECMAScript as implemented by JavaScript
1.x in Mozilla/Netscape or by JScript in IE does not know any classes
or class based inheritance.
As for documentation of behaviors and HTCs (HTML components) for IE:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/behaviors_node_entry.asp>
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/htcref.asp>
Many, many thanks for the pointers, and for your concern!
Martin Honnen

Best regards,

Arnaud

Sep 6 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.