[thelist] How do I know if a piece of JS is DOM or browser specific?

Peter-Paul Koch gassinaumasis at hotmail.com
Tue Oct 15 17:24:01 CDT 2002

> >> I'm trying to learn how to play with the DOM, but I want to avoid
> >> any browser specific stuff and code "W3C" DOM.
> >
> > For the moment you cannot ignore browser specific stuff, or your
> > sites won't work in Netscape and Explorer 4.
>I have the luxury of not caring :-)
>The site I am working on is a personal just for myself, and will be
>XHTML served as application/xhtml+xml which means that even IE6 won't
>even be able to handle it, nevermind earlier browsers.

That *is* a luxury. Very well, you don't need the browser specific DOMs.

> > If they work in all browsers they're valid.
>'all browsers'?  I'm sure this means that you have to choose what subset of
>browsers you are going to support/test on...

Depends. In a narrow sense, yes, of course you're right. However, see below
for more remarks. Besides, graceful degradation of JavaScript functionality
is an important principle, too.

>What about Mozilla 2, Internet Explorer7?  Opera 8?  Konqueror 5?

We'll deal with them when they are released.

>My idea was to start learning the "standards" so as to not end up with the
>javascript equivalent of using tables for layout, only to have to un-learn
>bad habits later.

This is not an exact comparision. Take forms, for instance. In the newest
browsers you can access a form by


and your form validation script will work. However, this is not the best way
to access forms. Simple form validation *can* work in Netscape 2, and
therefore, in my opinion, *should* work in Netscape 2. This means that you
have to use the old Level 0 DOM


In general you should use the Level 0 DOM (the one that Netscape
standardized before W3C existed) whenever possible. This is the best way to
program JavaScripts.

> > There is no validator or such for JavaScript, thank God.
>Well I figgered as much... suppose it would be pretty hard to do.  The nice
>thing about the validator is that you can say "Hey, I wrote this to the
>standards, it's your browser that's broken."

Having said that, you still need to code a workaround if, for instance, IE's
implementation is broken.

If JavaScripting is purely a hobby for you, you don't need to bother about
this, of course, but I will never officially recommend this practice <g>.

>Since my primary browser is Opera, I'm also trying to figure out where it
>needs to improve its support for JS/EMACScript/DOM.

It needs to be able to redraw pages without reloading them. Understanding
the Opera 7 pre-publicity correctly, it will support exactly this.

> > I think you should start with a simple JavaScript book. First get the
> > basics, don't worry too much about the DOM. Then, when you can write
> > simple scripts, go on to more complex things like DHTML, and only
> > then tackle the W3C DOM.
>Given the above, is that still your recommendation?


>Most of the examples I've seen are of the type:
>"Ok, now if you want to do X, you do A for NN4, B for IE4, C for IE5, and D
>for all others."

When dealing with DHTML in the Version 4 browsers, yes, this is the way to
go about it.

Maybe it would be best for you to stick to the W3C DOM and the Level 0
(Netscape) DOM and forget about intermediate stuff like document.all and
document.layers . Don't forget about Level 0, though. It's much simpler than
the W3C DOM and not using Level 0 where you could use it is bad coding
practice, in my opinion.

>That said, if there are good JS books that teach principles, etc, I'd love
>to hear what they are... searching for "DOM" in Google can be
>inefficient at best and.... err.... um... surprising, shall we say, at
>worst.... suffice it to say I've familiarized myself on how to tell
>Google to /exclude/ some things from search results :-)
>What would you consider a good 'simple JS book'?

The problem is that simple JS books aren't written for your situation but
for people who want to learn JavaScript in a hurry to code sites for money,
which means cross-browser compatibility goes before anything else.

I recommend the Glasshaus book, "Practical JavaScript for the Usable Web" by
Wilton, Williams and Li. It strikes the right balance between theoretical
and practical information.


Get a speedy connection with MSN Broadband.  Join now!

More information about the thelist mailing list