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 7 2181
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 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
"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.
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/
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
"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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert |
last post by:
Hi,
I can use "with" like this:
function MyObject(message)
{
this.message = message;
}
function _MyObject_speak()
{
|
by: stephane |
last post by:
Hi all,
What I am trying to achieve is an 'inherits' method similar to Douglas
Crockford's (http://www.crockford.com/javascript/inheritance.html) but
that can enable access to the superclass'...
|
by: jemptymethod |
last post by:
http://htmatters.net/htm/1/2006/01/EIBTI-for-Javascript-explicit-is-better-than-implicit.cfm
|
by: petermichaux |
last post by:
Hi,
I've been reading the recent posts and older archives of
comp.lang.javascript and am surprised by the sentiments expressed about
the prototype.js library for a few reasons:
1) The library...
|
by: eman1000 |
last post by:
I was recently looking at the prototype library
(http://prototype.conio.net/) and I noticed the author used the
following syntax:
Object.extend(MyObj.prototype, {
my_meth1: function(){},...
|
by: shypen42 |
last post by:
Hi all,
I'm very confused by the relation between "prototype" and
that "Prototype.js" library that seems to be used quite a lot
(not by knowledgeable people from this group if I understood...
|
by: Daz |
last post by:
Hi everyone.
My query is very straight forward (I think).
What's the difference between
someFunc.blah = function(){ ; }
and
|
by: burningodzilla |
last post by:
Hi all - I'm preparing to dive in to more complex application
development using javascript, and among other things, I'm having a hard
time wrapping my head around an issues regarding "inheritance"...
|
by: Robert |
last post by:
Hi,
I thought I pretty much understood the whole prototype chain stuff,
but now I stumbled upon a difference between IE and Firefox, that
is totally confusing me.
An example.......
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |