| Active Articles |
| Home > > Dynamically Loading Style Sheets |
|
Dynamically Loading Style Sheets
Browser sniffing is a long-established JavaScript practice. Before CSS came to the forefront,Web developers had to cope with a plethora of browsers, each with its own mix of standard HTML and proprietary tags. Many designers found creating multiple versions of their sites to be an onerous, but necessary, task.Which version of the site was served to the visitor depended on JavaScript code to detect the browser version and redirect accordingly.
The Web has grown wildly in intervening years, and the creation and ongoing maintenance of browser-specific site editions is no longer efficient or necessary.With the rise of standardscompliant browsers, more and more designers have switched to using CSS—a switch that JavaScript is ready to help with.Today, browser sniffers are largely used to detect the current browser so that the proper style sheet can be employed. Maintaining a series of style sheets is ar more feasible than keeping up with the updates for a number of variations of an entire site.
Determining Browsers with JavaScript Objects
Two basic approaches to detecting browsers exist. One method depends on the idiosyncrasies of individual browsers and their support of JavaScript objects. This method looks to see if one or more specific objects are supported by the browser currently being used. Depending on the nswer, you can figure out the browser name and version. For example, Netscape 4 is the only browser that supports the
document.layers object, and so this type of code is possible:
if (document.layers) {
// Netscape 4 code goes here
}
By calling the JavaScript object itself, either true or false is returned. If true is returned, the object is supported; if false is returned, it’s not.
Table shows a breakdown of objects and browser support.

Dynamically Loading Style Sheets is viewed 291 times
|
|