c-- styles for logos and headline links do not modify internet, red, or black styles -->
|
|
|
|
|
|
This
is page [4]
Alternatively, you can do the
same branching strictly via client-side scripting. Depending on the
amount of granularity you wish to establish for different browser
brands and versions at your site, you have many branching techniques
to choose from. All these techniques are based on a predominantly blank
page that has some scripted intelligence behind it to automatically
handle JavaScript-enabled browsers. Any script-enabled browser can execute
a script that looks into the visitor's browser version and loads the
appropriate starter page for that user. Example 2-1
shows one example of how such a page accommodates both scripted and
unscripted browsers.
Example 2-1: Branching Index Page
For browsers that either don't have JavaScript built in or have JavaScript
turned off, a <META> tag refreshes this page after one second
by loading a starter page for unscripted browsers. For "bare bones"
browsers that may not recognize scripting or <META> tags (including
Lynx and browsers built into a lot of handheld devices), a simple image
link leads to the unscripted starter page. Users of these browsers will
have to "click" on this link to enter the content portion of the web
site.
Example 2-1 is an extreme example. It assumes that
the application has as many as four different paths for four different
classes of visitor. This may seem like a good idea at first, but it
seriously complicates the maintenance chores for the application in
the future. At best, it provides a way to filter access between DHTML-capable
browsers and all the rest.
Example 2-2: Internal Branching for Browsers
DHTML feature sets that you can use as starting points for a common
denominator approach are the standards for Cascading Style Sheets Level
1 and CSS-Positioning. When you peruse the documentation from the browser
vendors in this arena, it is nigh impossible to distinguish support
for the recommended standard from a company's proprietary extension
that adheres to the spirit, but not the letter, of the standard. Just
because a feature is designated as being "compatible with CSS" does
not mean that it is actually in the published recommendation. Refer
to the reference chapters in Part II of this book for accurate information
on the implementations in the browsers as it relates to the standards.
You are likely to encounter situations in which the same style sheet
syntax is interpreted or rendered slightly differently in each browser.
This is one reason why it is vital to test even recommended standards
on both browser platforms. When an incompatibility occurs, there is
probably a platform-specific solution that makes the result look and
behave the same in both browsers. To achieve this parity, you'll need
to use internal branching for part of the page's content. This is still
a more maintainable solution than creating an entirely separate page
for each browser.
Some features that are available in one browser cannot be translated
into the other browser. Internet Explorer 4 includes a few DHTML capabilities
that have no parallel features in Navigator 4. Therefore, don't expect
to find common denominators for dynamic content (beyond swapping images
of the same size), transitions, or filters. DHTML facilities in Navigator
4 can be re-created in IE 4 either directly or via internal branching.
For example, the IE 4 <IFRAME> element closely resembles the Navigator
4 <ILAYER> element.
If this short lesson in finding a common denominator of functionality
reveals anything about the Version 4 browsers, it is that if you start
your design with Navigator 4 in mind, you can probably develop an IE
4 version using some or all of the techniques described in this chapter.
But if you start with IE 4 and get carried away with its DHTML features,
you may be disappointed when you run your application in Navigator 4.
Once you go to the trouble of writing scripts that perform internal
branching, you might prefer to avoid doing it again for the next document.
Both browsers allow JavaScript to load libraries of script functions
(files named with the .js extension) that you can link into any HTML
document you like. You can therefore create your own meta language for
scripted DHTML operations by writing a set of functions whose terminology
you design. Place the functions in a library file and rely on them as
if they were part of your scripting vocabulary. The language and function
set you create is called an application programming interface-an API.
Example 2-3 shows a small portion of a sample DHTML
API library.
Example 2-3: Portion of a DHTML Library
The The more interesting function in Example 2-3 is
shiftTo(), which changes the position of an object, so that it is located
at the specific coordinates that are passed as parameters. Each browser
has its own way to set the position of an object in a script. Navigator
4 features a one-step moveTo() method of a layer object; IE 4 requires
setting the pixelLeft and pixelTop properties of the object's style
property. Those differences, however, are handled by the function. Any
time you need scripted control of the movement of an item in a document,
you can call the shiftTo() function to do the job in whatever browser
is currently running.
Building an API along these lines lets you raise the common denominator
of DHTML functionality for your applications. You free yourself from
limits that would be imposed by adhering to 100% syntactical compatibility.
[In Chapter 4 of Dynamic HTML: The Definitive Reference, Goodman
presents a custom API that smooths over potentially crushing CSS-Positioning
incompatibilities. -Ed.]
Before undertaking cross-platform DHTML development,
be sure you understand that the features you can exploit in both browsers
- regardless of the techniques you use - are limited to comparable
feature sets within the realms of style sheets, positionable elements,
event models, object models, and downloadable fonts. Dynamic content on a small scale is also a cross-platform possibility,
but the instantaneous reflowing of modified content, display filters,
and transitions that are available in Internet Explorer 4 have no
parallels in Navigator 4. |
From
a maintenance point of view, the ideal DHTML page is one that uses
a common denominator of syntax that both browsers interpret and
render identically. Internet Explorer 4 includes a few DHTML capabilities that have no parallel features in Navigator 4. Therefore, don't expect to find common denominators for dynamic content (beyond swapping images of the same size), transitions, or filters. The Author Danny Goodman has been an active participant on the editorial side of the personal computer and consumer electronics revolutions since the late 1970s. His articles in the field have appeared in some of the most prestigious general audience publications and he has written dozens of feature articles for leading computer publications, such as PC Magazine, PC World, Macworld, and MacUser. Danny is currently a monthly columnist for Netscape Communication's online developer newsletter, View Source. He is also the author of more than two dozen books on computing and information superhighway technologies, including the popular JavaScript Bible.
|