Web hosting account - 1265Chapter 47 .Cross-Browser Dynamic HTML Issues As soon
1265Chapter 47 .Cross-Browser Dynamic HTML Issues As soon as the variable contains a valid reference to the object for the current platform, your scripts can treat the object without further concern for platform when addressing properties that have the same name in both platforms: instrux.visibility = hidden The nested layer situation is not the only potential problem for the platform equivalency approach. In fact, the W3C DOM format for referencing objects (using the document.getElementById()method) makes for some hair-raising string assembly and global variable assignment. Another truly negative aspect is the frequent usage of the eval()function. As mentioned in Chapter 42, this function is a performance speed thief. Modern approaches to compatibility While in-line branching and platform equivalency were suitable for their generations, the profusion of browser versions calls for better approaches to simplifying authoring for multiple DOMs. Techniques more suitable for today object detection and custom APIs are not really new. But these techniques are the preferred way to build cross-browser scripts with an eye to compatibility both backward and forward. Object detection The subject of object detection has been mentioned in several places in earlier chapters of this book. The technique has been used for a long time to let a browser not equipped to handle image objects gracefully skip over image swapping script segments: if (document.images) { // statements to work with image objects } If there is no document.imagesproperty for a browser, the condition evaluates to undefined, which the condition treats as being false. But object detection has also been misused in the past, especially in the DHTML realm, to substitute for browser version detection. For example, if a browser supported the document.allcollection, a global variable was set to indicate that the browser was IE4 or later; the existence of document.layers supposedly meant that the browser was NN4. While both of those assertions are true (as of the browsers released so far), it was a mistake to link a browser version with the existence of an object or property. Instead, object detection should be used only if your script statements will be addressing that object, just as the document.imagescondition does in the previous example. To demonstrate this tactic, consider the need to assemble a reference to an object so that it is ready to have one of its DHTML properties adjusted. Each of the three DOMs has its own syntax for assembling such a reference, and each syntax relies on the existence of a particular object or property. The function shown in Listing 47-1 (not on the CD-ROM by itself, but included in Listing 47-2) lets you pass the name or ID of a positioned element (either in string form or object form) to receive back a valid reference to the object with which style-related properties are associated all without resorting to the eval() function in any form:
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.