469,929 Members | 1,811 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

get prototype name of object in IE?

Hi all,

Does anyone know of a way in IE to determine the prototype name of an
object?

For instance, in Mozilla, I can say:

junk = document.getElementById("myID");
alert(junk.toString());

and it will tell me "[object <object name>]". In IE, I only get
"[object]".

How do I get the prototype name of an object in IE? Is there a way?

Brian

Jul 20 '05 #1
7 2050
Brian Genisio wrote:
Hi all,

Does anyone know of a way in IE to determine the prototype name of an
object?

For instance, in Mozilla, I can say:

junk = document.getElementById("myID");
alert(junk.toString());

and it will tell me "[object <object name>]". In IE, I only get
"[object]".

How do I get the prototype name of an object in IE? Is there a way?

Brian


I used the following code to generate a list of all attributes of "junk":

<span id="myID">x</span>
<script>
var junk = document.getElementById("myID");
var s = [];
for (var i in junk) {
s.push(i + ' = ' + junk[i]);
}
document.write(s.join('<br>'));
</script>

Then looked for something that could tell me what kind of HTML element
"junk" is. It appears junk.tagName reveals that information as "SPAN". I
then tested the same code in Mozilla Firebird 0.7, and it also has a
property called tagName, with the same value.

So for IE and Gecko-based browsers, you can use:

var junk = document.getElementById("myID");
if (junk != null) {
var htmlTag = junk.tagName;
}

Unfortunately, Opera 7.23 does not contain a tagName attribute, and using
alert(junk.toString()) produces the incredibly unhelpful [object
HTMLElement].

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2
Unfortunately, Opera 7.23 does not contain a tagName attribute, and using
alert(junk.toString()) produces the incredibly unhelpful [object
HTMLElement].


Hmmmm... I am not sure you understand what I am looking for. tagName is
not what I am looking for. The tagName element, part of the DOM spec
for HTMLElements, tells exactly that... the tag name.

So, for <HTML>, you will get HTML. Although that is useful to some, I
am looking for the actual object name... in this case, it would be
HTMLHtmlElement in Mozilla. It tells me so, if I say
htmlObject.toString(). More specifically, it says [object
HTMLHtmlElement].

That is, precisely, what I am trying to get from IE. I dont want to
know the tag name... I want to know the object name. Anything that is
not an element does not have the tagName option, so would fail if you
called the tagName.

Note: This is not for scripting purposes... it is for my own
documentation purposes.

Thank you,
Brian
Jul 20 '05 #3
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:40***************@agricoreunited.com...
<snip>
Unfortunately, Opera 7.23 does not contain a tagName attribute, ...

<snip>

I think you will find that Opera does have a tagName property and your
script is not finding it because Opera is less than forthcoming with -
for(var prop in obj) - loops with host objects.

Richard.
Jul 20 '05 #4
On Wed, 04 Feb 2004 15:54:24 -0500, Brian Genisio
<Br**********@yahoo.com> wrote:
That is, precisely, what I am trying to get from IE. I dont want to
know the tag name... I want to know the object name.


It doesn't do the same, you can create it with

IHTML str Element

replacing " str " with the tagname - I can't possibly see the point of
it though, and there may well be some exclusions to that anyway.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5
Jim Ley wrote:
On Wed, 04 Feb 2004 15:54:24 -0500, Brian Genisio
<Br**********@yahoo.com> wrote:

That is, precisely, what I am trying to get from IE. I dont want to
know the tag name... I want to know the object name.

It doesn't do the same, you can create it with

IHTML str Element

replacing " str " with the tagname - I can't possibly see the point of
it though, and there may well be some exclusions to that anyway.

Jim.


Thanks for the try... but that is still not what I am looking for.

Every object type in JavaScript is a single type, an object. This is
why when you say typeof myObject, you get "object", no matter what it is.

With each object, there exists a prototype. That prototype defines the
object name (HTMLHtmlElement, DOMNode, DOMElement, HTMLElement, etc), as
well as the properties and methods (which are really function object
properties) associated with the object.

When you do a myObject.toString in Mozilla, it prints the prototype name
of the object, such as HTMLHtmlElement. (toString is overridden for a
few objects, such as the Location object).

Anyways, I am looking to see if there is any way to get that value. The
ECMA binding for the DOM specification calls out the types that are to
exist, such as DOMNode, DOMElement, HTMLElement, HTMLHtmlElement,
DOMDocument and HTMLDocument. It does not call out the more specific
object names, such as the Location, History, Navigator and Window objects.

I am trying to get these values, so I can know what IE calls them.

I know it is cooky, and I know it looks like there is no good reason to
get that information, but I promise it is useful to me. Although, I can
live without it as well :)

Thanks,
Brian

Jul 20 '05 #6
"Brian Genisio" <Br**********@yahoo.com> wrote in message
news:40********@10.10.0.241...
<snip>
With each object, there exists a prototype. That prototype
defines the object name (HTMLHtmlElement, DOMNode, DOMElement,
HTMLElement, etc), as well as the properties and methods (which
are really function object properties) associated with the object.
ECMAScript distinguishes Host Objects from Native Objects (section
4.3.6-8) and makes no requirements of Host Objects. All of the DOM nodes
are Host Objects so whether they have prototypes or not is left up to
the implementers to decide. Some have decided that they will, others
have decided that they don't (or not to expose those properties to
scripts).

<snip>Anyways, I am looking to see if there is any way to get that
value. The ECMA binding for the DOM specification calls out
the types that are to exist, such as DOMNode, DOMElement,
HTMLElement, HTMLHtmlElement, DOMDocument and HTMLDocument.
It does not call out the more specific object names, such as
the Location, History, Navigator and Window objects.

<snip>

The W3C specifications define HTMLElement, HTMLHtmlelement, etc. as
interfaces and not classes. It is completely practical for a Javascript
object to be no more than an object (with Object.prototype as its
prototype) and still implement any interface.

Richard.
Jul 20 '05 #7
Brian Genisio <Br**********@yahoo.com> wrote in message news:<40********@10.10.0.241>...
hi Brian,
With each object, there exists a prototype. That prototype defines the
object name (HTMLHtmlElement, DOMNode, DOMElement, HTMLElement, etc), as
well as the properties and methods (which are really function object
properties) associated with the object.
what you call prototype is the constructor of an object.
When you do a myObject.toString in Mozilla, it prints the prototype name
of the object, such as HTMLHtmlElement. ( ... ).


for objects in mozilla thats types get identified by the "typeof"
operator as "object" the "toString" method in mozilla returns this
type and additionally, separated by a blank, the objects constructor
name (arrays will be traeted differently);

your problem can't be solved since you are looking for the constructor
property of html node elements in msie, but this browsers node objects
have not implemented the constructor property. for this you won't be able
to assamble a "toString" method for msie that would bahave mozilla like.

proof it:

alert(document.getElementsByTagName("body")[0]);
returns "[object]" in msie6 and "[object HTMLBodyElement]" in mozilla.

alert(document.getElementsByTagName("body")[0].constructor);
returns "undefined" in msie6 and "[HTMLBodyElement]" in mozilla.
so long - peterS. - ps******@gmx.net
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Robert | last post: by
4 posts views Thread by jemptymethod | last post: by
12 posts views Thread by petermichaux | last post: by
13 posts views Thread by eman1000 | last post: by
11 posts views Thread by shypen42 | last post: by
6 posts views Thread by burningodzilla | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.