|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Browser Detection ScriptsBefore we turn our attention to Cross-Browser Dynamic HTML (which, for the sake of brevity, we will abbreviate CBDHTML), one more topic should be discussed. The key to developing HTML documents that implement CBDHTML functions correctly on multiple browsers and platforms and that degrade gracefully on older or third-party browsers is the capability to successfully detect the Web browser being used. Again, many solutions are freely available that solve this problem; one of the most extensive is Netscapes Ultimate JavaScript Client Sniffer, which you can download from http://developer.netscape.com/docs/examples/javascript/browser_type.html. When included within an HTML document and evaluated on the client Web browser, the Client Sniffer creates an is object with a series of properties that can be used in your scripts to detect the browser type and platform being used to view your document. Figure 27.1 shows Netscape Navigator version 4.05, running on Windows 95, viewing the Web site at the URL given in the previous paragraph.
The way the Ultimate JavaScript Client Sniffer would be used in an HTML document is to include, and then to use, the properties of the is object to conditionally write HTML code depending on the detected browser type and platform. The following JavaScript code snippet shows an example: var is = new Is(); if (is.nav4up) JavaScript document.write statements to write Navigator 4+ code… if (is.ie4up) JavaScript document.write statements to write Internet Explorer 4+ code… Formatting with Style SheetsThe W3Cs CSS1 style sheet specification was one of the first technologies considered a part of Dynamic HTML that was agreed to by both Netscape and Microsoft. Even so, none of their browsers various versions or platforms fully implement the specification, nor do they implement everything in the same way. Also, although both implementations of Dynamic HTML expose the style sheet properties to scripting, the Document Object Model that does this is different for each. So, the first step to take before using style sheet properties in a Web page meant to be cross-browser compatible is to make sure you use those properties that are consistently implemented in each. Fortunately, this task is made easier by some online resources. At http://style.webreview.com/ you can find a compilation of style sheet properties that are considered safe for cross-browser deployment. Figure 27.2 shows part of the grid of safe properties, showing browser and platform and whether the property is completely (indicated by Y) or partially (indicated by P) safe.
With either Web browser, it is possible to specify style sheet properties one of two ways. The first of these, which is using CSS1 style sheet syntax, is the same on both browsers. To specify a style sheet class that gives an element a yellow background color, for example, you could use the following on either browser: <STYLE TYPE=text/css> .bgyellow {background-color: yellow} </STYLE> If you want to conditionally set style sheet properties depending on some condition, you cant use CSS1 syntax because style sheet properties specified through CSS1 syntax are static. To set these properties dynamically, you need to use JavaScript and the Document Object Model for the appropriate browser.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |