95Chapter 14 .Document Object Model Essentials … This (Unable to start debugging on the web server)

95Chapter 14 .Document Object Model Essentials This technique obviates the need to use browser version detection because the functions invoked by the event handlers do not have to build DOM-specific references to the objects to adjust the style. Branching variables If, for now, you continue to be more comfortable with browser version detection than object detection, you can apply version detection for this middle ground scenario by establishing branches for the IE4+ and W3C object models. Global variables that act as flags elsewhere in your page s scripts are still the primary mechanism. For this scenario, you can initialize two global variables as follows: function getIEVersion() { var ua = navigator.userAgent var IEoffset = ua.indexOf( MSIE ) return parseFloat(ua.substring(IEoffset+5, ua.indexOf( ; , Ieoffset))) } var isIE4 = ((navigator.appName.indexOf( Microsoft ) == 0 && parseInt(getIEVersion()) >= 4)) var isW3C = (document.documentElement) ? true : false Notice how the getIEVersion()function digs out the precise IE version from deep within the navigator.userAgent property. Both global variables are Boolean values. While each variable conveys valuable information on its own, the combination of the two reveals even more about the browser environment if necessary. Figure 14-4 shows the truth table for using the AND (&&) operator in a conditional clause with both values. For example, if you need a branch that works only in IE4, the if clause is if (isIE4 && !isW3C) {…} isIE4 isW3C isIE4 && isW3C true true IE5+ true false IE4 Only false true NN6+ false false Older browser Figure 14-4: Truth table for two browser version variables with the AND operator The overlap between MS and the W3C object models in IE5 means that you need to determine for each branch which model to use when the script is running. This governs the order of nested if conditions when they arise. If you trap for the W3C version first, IE5 runs the branch containing the W3C DOM syntax.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply