To test a function with a Broser

P

Pietro

Hi at all,
I am looking for a mean to test if a function work with a certain Browser or
not.
I'ld like to make a funcrion that return true if the browse is compatible
with a certain funcrion or style and false if not.
Have you any idea?
Thank in advance an dbest regards.
Pietro.
 
L

Lasse Reichstein Nielsen

Pietro said:
I am looking for a mean to test if a function work with a certain Browser or
not.

Testing whether it works is harder than just testing whether it exists.
Existence is easy. E.g., to test for document.getElementById, you can
just do:

function existsDGEBI() {
return typeof document.getElementById == "function";
}
I'ld like to make a funcrion that return true if the browse is compatible
with a certain funcrion or style and false if not.

It might be easier to help, if you were a little bit more specific.

/L
 
P

Pietro

Hi Lasse,
the function that I'ld want to test is:
document.getElementById("object")
Is it possible to test therefore to know in advance if this function work in
any browser that the user can have?
Thanks
Pietro
 
L

Lasse Reichstein Nielsen

Pietro said:
the function that I'ld want to test is:
document.getElementById("object")

The function is "document.getElementById". Calling it gives a DOM
node, if there is one with that id.

I think it is safe to assume, that if the function exists, then it
also works correctly. That is, you can just do
if (document.getElementById) {
... it exists, do whatever you want with it...

/L
 
L

Lasse Reichstein Nielsen

The existence of document.getElementById doesn't imply you can "do
whatever you want with it". It only implies that the browser
supports getElementById, any further uses of it you still need to
test for.

If we want to take that line of thought to the limit, all it shows is
that the value of the property "document" of the global object is
itself an object (or is convertible to one), and that it has a
property called "getElementById" that has a value that is not
convertible to "false".

We might also need to check that "document" really refers to a
document, that getElementById is a function, and that it takes an
argument and returns a DOM node that has that argument as an ID
attribute.

We should also test that we are really running a version of
Javascript, and that the Javascript interpreter works correctly for
all the language constructs that we use.

This is ofcourse ridiculous. We have to draw a line somewhere, and
assume that everything below that line works to our assumtions.

What I say is that, in my opinion, which I prefer to think of as
informed, the line can be drawn at the existence of a "getElementById"
propertyin the "document" object (which is assumed to exist). If
"getElementById" exists, then I will use it and assume that it is
indeed an implementation of the method specified in the DOM 2 Core W3C
recommendation.

I haven't yet seen a browser where that assumption fails, and I don't
expect to see on.
Not the use of getElementById, but the methods of it need to be
tested as well.

What is the "use" and "methods" of "getElementById"?

/L
 
J

Jim Ley

Further use of elements must either be assumed to work or be checked
first, depending on what feature it is (e.g., changing the src
property of an image can be assumed to work, while changing the
src property of a script element can not be assumed to do anything).

I don't agree with this, I believe you should always check that what
you get back from gEBI is a node and null before you try doing
anything else, there are content modifying proxies, and there are
broken connections.

Jim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top