473,486 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

document.all

Hello,
1. The document.all property (array?) seems to be a popular IE-only
attribute. Other browsers (Opera, Mozilla) do not seem to care for it which,
of course, occasionally produces weird displays and non-functional links.
Is it, indeed, a IE-ism?

2. While experimenting with the elusive document.all, I ran into a sort of
catch-22, it least with Mozilla. I tried testing (null == document.all) to
decide if the property exists, and get a warning (in the Mozilla Javascript
console) that the property does not exist. Hm.
Is there a robust way to test for a property that may not exist? A way
that does not generate warnings or errors about that non-existence?

--
jim moe
Jul 20 '05 #1
5 3500
James Moe wrote:
Hello,
1. The document.all property (array?) seems to be a popular IE-only
attribute. Other browsers (Opera, Mozilla) do not seem to care for it
which, of course, occasionally produces weird displays and
non-functional links.
Is it, indeed, a IE-ism?
Yes.
2. While experimenting with the elusive document.all, I ran into a sort
of catch-22, it least with Mozilla. I tried testing (null ==
document.all) to decide if the property exists, and get a warning (in
the Mozilla Javascript console) that the property does not exist. Hm.
Thats because you are testing null against document.all, since
document.all doesn't exist in Mozilla, you get the error.

Is there a robust way to test for a property that may not exist? A way
that does not generate warnings or errors about that non-existence?


if (document.all)
{
//it exists
}

or

if (!document.all)
{
//it doesn't exist
}

depending on what you are doing.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 20 '05 #2
Randy Webb wrote:
Is there a robust way to test for a property that may not exist? A
way that does not generate warnings or errors about that non-existence?


if (document.all)
{
//it exists
}

Thank you.

--
jim moe
Jul 20 '05 #3
James Moe wrote:
1. The document.all property (array?) seems to be a popular IE-only
attribute. Other browsers (Opera, Mozilla) do not seem to care for it
Opera 7, and many other browsers do implement a document.all collection.
But most also support a W3C DOM standard alternative (as do recent IE
versions) so their use should be preferred and document.all relegated to
the status of potential fall-back for 2 or 3 dinosaur browsers.
which, of course, occasionally produces weird displays and
non-functional links. Is it, indeed, a IE-ism?
It certainly originated at Microsoft in IE. Its imitation by many other
browsers was out of expedience rather than need.
2. While experimenting with the elusive document.all, I ran into a
sort of catch-22, it least with Mozilla. I tried testing
(null == document.all)
Comparison with - null - is not the best test. A direct type-converting
to boolean test will produce false for null and undefined and true for
objects and functions.
to decide if the property exists, and get a warning (in
the Mozilla Javascript console) that the property does not exist. Hm.
Yes, they are berks! They are attempting to apply warning criteria that
make prefect sense when authoring for a known environment in a
non-dynamic language. An no doubt when they write javascript it is for
Mozilla, so they have a known environment and accessing an unimplemented
property would be a mistake. But cross-browser scripting has to exploit
the dynamic nature of javascript and applying an operation that will
type-convert an undefined property into a false boolean value is a
completely valid, normal and (for efficiency at least) desirable
operation.

If you are not writing exclusively for Mozilla ignore Mozilla's
warnings. If you want warnings relating to javascript authoring use
JSLINT.
Is there a robust way to test for a property that may not exist? A
way that does not generate warnings or errors about that
non-existence?


Yes, the - typeof - operator can be used for all testing, it is even
necessary to use it to verify some aspects of the environment, such as
determining if properties refer to primitive values because a
type-converting test will produce false results with empty strings,
numeric zero and boolean false (though no type converting is needed for
that). So - if(typeof pageXOffset == 'number') will tell you that the -
pageXOffset - property is implemented on the browser even when the value
of the number is zero (which it usually is, at least initially). But
notice that the - typeof - test is not one operation it is two, the -
typeof - operation itself followed by string comparison. String
comparison should be fairly quick if the strings don't match, comparing
the first letter will tell you that, but if they do match each letter is
going to have to be compared in turn and that is much more involved.

But when dealing with properties that may be implemented as object or
function a type-converting test will tell you what you want to know in
one quick and simple operation while - typeof - testing would require a
battery of tests to give the same information.

For example, consider the - nextSibling - property of DOM Nodes. The
possibilities are:-

1. It is not implemented, its value is - undefined -, so no attempt
should be made to use it.
2. It is implemented but there is no nextSibling object, the
property value is - null - (or possibly - undefined -, though
that is unlikely), so no attempt should be made to use it.
3. It is implemented and refers to a sibling Node, Possible typeofs
are "object" or "function" because of diverse host environment
implementations. It is safe to interact with the object.

Obviously the reason for testing the - nextSibling - property is to
decide whether to interact with the object. So the - tyoeof - test would
need to see if the returned string was either "object" or "function"
before acting on the node. But (typeof null == "object") so the test
would also have to differentiate between - null - and a real DOM node,
which takes a type-converting test. You can avoid the Mozilla warning by
doing the - typeof - testing first but the result is:-

if(((typeof node.nextSibling == 'object')||
(tyoeof node.nextSibling == 'function'))&&
node.nextSibling){
... // safe to use node.nextSibling.
}

So that is two - typeof - operations (though it could be got down to one
with an assignment to a local variable), two string comparisons and a
type-conversion (not to mention the logical operations) in order to find
out if it is possible to use the node. Compare that with a normal
type-converting test:-

if(node.nextSibling){
... // safe to use node.nextSibling.
}

It differentiates 100% between - null - and - undefined - on one side
and objects and functions on the other. And it is a completely legal
operation in javascript (and all ECMAScript implementations), indeed it
is optimum for the task.

If the authors of Mozilla don't know enough about javascript or browser
scripting to see that they are doing nothing more worthwhile that
burdening their (already often sluggish) browser with generating
meaningless warnings as the result of normal (even advisable) operations
then that is their own look-out. Giving in to their nonsense means
burdening every other browser in existence with inefficient code for no
good reason, and Mozilla is not the only browser in use.

Richard.
Jul 20 '05 #4
James Moe wrote:

1. The document.all property (array?) seems to be a popular IE-only
attribute. [snip]
Is it, indeed, a IE-ism?
Yes.
2. While experimenting with the elusive document.all, I ran into a sort
of catch-22, it least with Mozilla.[snip]

Using "document.all" is sort of risky, since a lot of browsers don't use
it at all. Its rather like trying to use your car ignition key to start
up a helicopter - its not possible, so don't even try.

--
Mark A. Preston
Jul 23 '05 #5
Richard Cornford wrote:
Is there a robust way to test for a property that may not exist? A
way that does not generate warnings or errors about that
non-existence?


Yes, the - typeof - operator can be used for all testing, it is even
necessary to use it to verify some aspects of the environment, such as
determining if properties refer to primitive values [...]

Thank you. That is what I was looking for.

--
jim moe
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2853
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
2361
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
2
1664
by: Edward | last post by:
The below code builds 2 tables 4 rows by 4 cols. All cells have checkboxes. When checked, the checkboxes in the first column automatically check the remainder of the check boxes in the same row. ...
1
2684
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
10119
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
4
5433
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
8
8195
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
5
2930
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
6
3354
by: therig | last post by:
I'm having issues, I've spent many hours searching and I'm a noob at javascript, any help will be greatly appreciated. I keep getting the following error: Error: document.forms.sec11_A has no...
4
2604
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
0
7105
marktang
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,...
0
7132
Oralloy
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,...
0
7180
jinu1996
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...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.