DHTML in
Netscape 4.x and
IE 4.x and higher is mainly different in that IE support dynamic styles, and
Netscape doesn't. They each have different
object model calls, and thus have to be dealt with
differently, but you can special case them in. What I typically do is in a function onload(), I detect the
browser string
var isNetscape = 0;
function myOnLoad()
{
if(navigator.appName == "Netscape")
{
isNetscape = 1;
}
else
{
isNetscape = 0;
}
}
Then whenever you need to make a call to a part of the
dynamic HTML model, then I
eval() a string for it to get the object. This way, there is never any incorrect syntax, especially if you use
typeof() information to deal with any object
failures.
In the realm of
dynamic styles, there are many workarounds, but most of them involve document.write. In IE, you can directly write to a
style (IE: name.style.property = newvalue), but in
NS, this does not accomplish
anything, with the exception beings the
visibility CSS attribute: You can always turn an object "on" or "off" depending on what you need to hide or show with it.
Therefore, to work around this limitation for other items such as color, size, or what not, you need to
inject new text where you want it; Netscape will change if you change the
source on it. Now,
document.write would normally write only to your top level
document (where the <body> tag would start). However, Netscape has made your life marginally easier by allowing you to consider any Layer item a body element. This means you can do document.body.layers.layername.document.write "new text". With a properly set up
JavaScript applet, you can place
layer tags in the correct spot, and re-inject the correct text where you need it, when you need it.
The modeling system of
NS is not as good as
IE. There are more complicated handlers for events, and the ability to define custom
events. Typically, only the Netscape <layer> tag can be affected at all at run time, while
IE allows all manner of
scripting, but prefers the nuetral tags <span> and <div>, because they do not affect
formatting in any way on their own.
The scripting
engines are also quite different. While they are both standard
JavaScript engines (although Microsoft calls theirs
JScript),
Microsoft's is both more
lenient and easier to
debug. Netscape's however is more noticeable in case of a
failure. Microsoft ships a debugger from their
MSDN Scripting website called
Microsoft Script Debugger that handles the task nicely, while Netscape has the clunky and strange
JavaScript console (accessible by typing in
javascript: into the browser). Both have their advantages; Microsoft's is a considerably nicer environment to get things
accomplished in, seeing as it gives you a readable error immediately when something goes wrong.
All in all working with two
established, competing
products in the same
realm is a difficult
chore. You choose the lowest common
denominator of
functionality between the two, and work from there. Another hurdle in the
DHTML world is that
standards mean nothing; both sides break them
somehow. It really comes down in the end to the smell of the dirt: who is implementing what. Your pages are
documents of the browser, and whether they work or not with shipped code is your
responsibility, not anyone else's. No one will blame Netscape or Microsoft when your app doesn't work.