My web server - 52 Part III . Document Objects Reference Object
52 Part III . Document Objects Reference Object detection works best when you know for sure how all browsers implement the object. In the case of document.images, the implementation across browsers is identical, so it is a very safe branching condition. That s not always the case, and you should use this feature cautiously. For example, IE4 introduced a document object array called document.all, which is used very frequently in building references to HTML element objects. NN4, however, did not implement that array, but instead had a document-level array object called layers, which was not implemented in IE4. Unfortunately, many scripters used the existence of these array objects as determinants for browser version. They set global variables signifying a minimum version of IE4 and NN4 based on the existence of these array objects. This is most dangerous because there is no way of knowing if a future version of a browser may adopt the object of the other browser brand. What happens, for instance, if the W3C DOM in a future version should adopt the document.all array? If a future version of Navigator implements that array, the browser sniffing code from the old page will treat Navigator as if it were Internet Explorer, and scripts will likely break left and right. This is why I recommend object detection not for browser version sniffing but for object availability branching, as shown previously for images. Moreover, it is safest to implement object detection only when all major browser brands (and the W3C DOM recommendation) have adopted the object so that behavior is predictable wherever your page loads in the future. Techniques for object detection include testing for the availability of an object s method. A reference to an object s method returns a value, so such a reference can be used in a conditional statement. For example, the following code fragment demonstrates how a function can receive an argument containing the string ID of an element and convert the string to a valid object reference for three different document object models: function myFunc(elemID) { var obj if (document.all) { obj = document.all(elemID) } else if (document.getElementById) { obj = document.getElementById(elemID) } else if (document.layers) { obj = document.layers[elemID] } if (obj) { // statements that work on the object } } It no longer matters which browser brand, operating system, and version supports a particular way of changing an element ID to an object reference. Whichever of the three document object properties or method is supported by the browser (or the first one, if the browser supports more than one), that is the property or method used to accomplish the conversion. If the browser supports none of them, then no further statements execute. If your script wants to check for the existence of an object s property or method, you may also have to check for the existence of the object beforehand if that object is not part of all browers object models. An attempt to reference a property of a non-existent object in a conditional expression generates a script error. To avoid
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.