Java Reference
In-Depth Information
A Brief Look at Browsers and Compatibility
Problems
You've seen in the preceding example that by using JavaScript you can change a web page's document
background color using the bgColor property of the document . The example worked whether you used
a Netscape or Microsoft browser, because both types of browsers support a document with a bgColor
property. You can say that the example is cross-browser compatible . However, it's not always the case that
the property or language feature available in one browser will be available in another browser. This is
even sometimes the case between versions of the same browser.
The version numbers for Internet Explorer and Firefox browsers are usually written as a decimal
number; for example, Firefox has a version 1.5. This topic uses the following terminology to refer to
these versions: By version 1.x we mean all versions starting with the number 1; by version 1.0+ we
mean all versions with a number greater than or equal to 1.
One of the main headaches involved in creating web-based JavaScript is the differences between differ-
ent web browsers, the level of HTML they support, and the functionality their JavaScript interpreters
can handle. You'll fi nd that in one browser you can move an image using just a couple of lines of code
but that in another it'll take a whole page of code or even prove impossible. One version of JavaScript
will contain a method to change text to uppercase, and another won't. Each new release of IE or Firefox
browsers sees new and exciting features added to its HTML and JavaScript support. The good news is
that to a much greater extent than ever before, browser creators are complying with standards set by
organizations such as the W3C. Also, with a little ingenuity, you can write JavaScript that will work
with both IE and Firefox browsers.
Which browsers you want to support really comes down to the browsers you think the majority of your
web site's visitors, that is, your user base, will be using . This topic is aimed at both IE7 and later and
Firefox 2 and later.
If you want your web site to be professional, you need to somehow deal with older browsers. You could
make sure your code is backward compatible — that is, it only uses features available in older browsers.
However, you may decide that it's simply not worth limiting yourself to the features of older browsers. In
this case you need to make sure your pages degrade gracefully. In other words, make sure that although
your pages won't work in older browsers, they will fail in a way that means the user is either never
aware of the failure or is alerted to the fact that certain features on the web site are not compatible with
his or her browser. The alternative to degrading gracefully is for your code to raise lots of error mes-
sages, cause strange results to be displayed on the page, and generally make you look like an idiot who
doesn't know what you're doing!
So how do you make your web pages degrade gracefully? You can do this by using JavaScript to deter-
mine which browser the web page is running in after it has been partially or completely loaded. You
can use this information to determine what scripts to run or even to redirect the user to another page
written to make best use of her particular browser. In later chapters, you see how to fi nd out what fea-
tures the browser supports and take appropriate action so that your pages work acceptably on as many
browsers as possible.
Search WWH ::




Custom Search