|
|

|
|
Scripting for 5th Generation Browsers - Part 1
|
|
IntroductionThe release of NS6 has been a hotly debated topic on the net. At the center of this debate have been claims of lack of functionality and usability. To an extent these claims are accurate as the browser does have some usability issues, e.g. non-functional rollovers, as one example. However, approaching Netscape 6 from this negative perspective and focusing on the things that do not work is a limiting viewpoint. It is limiting because ‘we’ as web developers tend to loose sight of the bigger picture and consequently do not focus on what the browser can do in terms of coding practices.
This bigger picture entails a web that allows developers to code by a singular standard. Herein lies the beauty of Netscape 6, a standards compliant browser, a factor that often seems to get lost in the usability debate. Consequently, for the first time on the WWW, developers can mostly focus on coding by a singular standard rather than having to work their way through a number of conditional JavaScript statements to cater to different browser requirements. I say mostly, because there are still some specific situations where DOM switches catering for Internet Explorer 5+ and Netscape 6 need to be provided, e.g., detecting a browsers height and width. In the main though a web developer’s focal point can be centered upon coding by a singular standard, which represents a considerable improvement in coding techniques.
Code ReductionOne of the biggest benefits of coding for IE5+ and Netscape 6 is the code reduction that is obtained by not having to include conditional branches (e.g. If else statements). For example, let us suppose we wanted to dynamically change the background color of a layer in Netscape 4, Internet Explorer 4 and Netscape 6. We would have to create conditional statements to cater for the different Document Object Models as demonstrated in the below example: <> <> <> <However, if you wanted to code by W3C standards the above script would translate to such: <> <> <> <View example As is demonstrated in the above example, there is a considerable reduction in the code. The above script functions in Internet Explorer 5+ and Netscape 6 as these both support the W3C DOM document.getElementById() method. At last a standard way of scripting that is compatible in both browsers! From my perspective, that is the real benefit of coding in such a manner. What Is A Standard Anyway?I have already mentioned coding by W3C standards, but what makes more sense to me is that the standard that matters most is what is currently supported by both browsers without having to rely on proprietary methods and consequently conditional branches. That is not to say I am not an advocate of W3C standards, because the reality is I believe in this fundamental concept and support it as much as possible.
<> <> <> <View example For all intents and purposes the standard that matters most is what is common to both browsers. At least that is how I typically approach things; to find the common denominator for both browsers. In many ways, the future looks a lot brighter as more DOM related methods get implemented into browsers. For example, Internet Explorer 6 now supports the replaceData() method which is handy for manipulating text strings. Try this example in Internet Explorer 6: Extracting DOM Substrings In fact if you work through the DOM tips examples at Javascript Tip archive you will find that quite a few things that were not working in Internet Explorer 5 and 5.5 now work with Internet Explorer 6. The point being that common standards between browsers are frequently being updated and it's a developers "duty" to keep a keen eye on the changes that are occurring. Thus it is not just the W3C we need to keep an eye for new recommendations, but also what the new browsers have in common that fall outside of the W3C recommendations realm. Both are equally important. For the moment though we need to focus on the here and now, so let us begin by taking a look at how to retrieve elements. Retrieving ElementsThe two most common methods of retrieving elements based on the W3C DOM are
the <would be retrieved with JavaScript by using
theDiv = document.getElementById('eddieLayer').style
We can then utilize the variable theDiv to dynamically manipulate
the style attributes of the < |