Essay Preview: HtmlReport this essayDEALING WITH BROWSER DIFFERENCESThe W3C has revolutionized DHTML by making a single standard that both Netscape and Microsoft have committed to support. Nevertheless, neither supports it perfectly yet, and many users use old browsers. If your page relies on DHTML, you will need to account for all of these possibilities.

DHTML BROWSER DIFFERENCESBack when the version 4.0 browsers were the latest thing, there were major differences between their supports for DHTML. If you wrote an application using DHTML for Internet Explorer 4.0, there were no chance at all it would work on Netscape 4.0.

Things are different now with the W3C DOM. Since both Internet Explorer 5 and later, and Netscape 6 and later are based on this standard, if you write an application for one of these browsers the chances are good it will work on the other.

However, neither browser supports 100% of the W3C DOM standard. As you use more specific properties and attributes, the chance increases that youll run into a difference between the browsers.

There are two key things you can do to make sure the latest DHTML browsers support your scripts: First, test script in as many different browsers as possible. At the very least, you should have the latest version of Netscape and Internet Explorer available.

Second, you can use JavaScript to detect the users current browser or the features it supports; you deal with difference by writing code for different browsers. Using this technique, you can support older browsers, as well as the latest.

DETECTING BROWSERSIf you plan to support more than one browser – or even if youre restricting your page to certain browsers – youll need a way to detect which browser is in use. You can do this in one of two ways:

Detecting the exact browser in use (browser sensing)Detecting whether a feature is supported (feature sensing)BROWSER SENSINGThe most obvious way to detect which browser is in use is to use the navigator object, which is supposed to contain a concise list of information about the users browser. Listing 17.1 shows a simple script that displays the values of several navigator properties.

Listing 17.1Displaying Information About the BrowserBrowser InformationBrowser InformationThe navigator object contains the following informationAbout the browser you are using.document.write(“Code Name: ” + navigator.appCodeName);document.write(“App Name: ” + navigator.appName);document.write(“App Version: ” + navigator.appVersion);document.write(“User Agent: ” + navigator.userAgent);document.write(“Language: ” + navigator.browserLanguage);document.write(“Platform: ” + navigator.platform);FEATURE SENSINGSupposed youve used browser sensing to check the Internet Explorer 5 or Netscape 6. Now supposed that Netscape has released version 7, Internet Explorer has released version 7.5 and Opera has released a version that supports DHTML better than either one. Chances are, one or more of these new browsers wouldnt work with your script.

To account for situation like this, you can see feature sensing rather than browser sensing. By detecting the specific DHTML features you plan to use, you can determine whether the current browser supports them – without necessarily knowing which browser it is.

Youve already seen an example of browser sensing in several of the example in this book:if (!document.getElementById) return;This statement checks whether the document.getElementById method exists. If it doesnt exist, it returns from a function. You can also use this technique to create a version of the script for older browsers, as youll see later in this hour.

If you include a statement like this before you actually use the document.getElementById method, you can avoid error messages in older browsers. You can use the same technique with document.getElementsMyTagName, or any other method or object your script will use.

USING FEATURE SENSINGUsing feature sensing, you can create simple script that checks whether the current browser support the W3C DOM or one of the older DHTML standards. Listing 17.2 shows the feature sensing example.

Listing 17.2Using Feature SensingBrowser Feature SensingBrowser FeatureThe information below was obtained using feature sensing:if (document.getElementById) {document.write(“This browser supports getElementById”);document.write(“, and appears to support the W3C Dom.”);} else document.write(“The W3C DOM is not supported.”);if (document.layers) {document.write((“This browser supports the layer arrays”);document.write(“, and is most likely Netscape 4.”);} else document.write(“The layers array is not supported.”);if (document.all) {document.write(“This browser supports the document.all array”);document.write(“, and is most likely Internet Explorer.”);} else document.write(“document.all is not supported.”);

The attribute and the attribute name of the function are: https://www.googleapis.com/.

As a side effect of a function’s implementation a user can select it to open in Internet Explorer, Firefox, Netscape, or Opera and get it in a second tab within an Internet Explorer window. If the value of an element is not available to the user’s browser it is taken through web browser’s settings to the function’s API. The elements can be changed using this mechanism, via web browser options.

If you change the attribute value with the attribute-binding, you get something like:

Link

The parameter is passed in as a string to this function. The attribute should begin with a single space, followed by the value with a valid value.

The attributes of this function are to be given, as the value returned by the function calls a function object.

#1035

#

#105

The number of characters to display in the HTML input for this function is a function identifier given by the attribute. The attribute is intended to support HTML5 attributes and also for any other applications that depend on a single HTML element.

#822

#

#876

#915

#915

#915

#915

#915

#915

#915

#915



                
Get Your Essay

Cite this page

Browser Differences And Else Document.Write. (August 13, 2021). Retrieved from https://www.freeessays.education/browser-differences-and-else-document-write-essay/