Joe Maller: JavaScript: JavaScript Browser DetectionAn overview about how JavaScript can detect browser properties. |
||
|
Compatibility issues sometimes require page authors to restrict access to a page to a specific set of web browsers. The concepts explained below can be used to build a browser detection script capable of just about anything. All Browsers are NavigatorsAll JavaScript browser detection is based on the "navigator" object, which could just be thought of as the browser. The name is a vestigial little piece of Netscape remaining in the JavaScript language. Netscape's first product was called Navigator, back before it got all kludged up with Communicator, news readers, e-mail and lots of things that didn't work very well. The Navigator element has properties that scripts can use to find out exactly what kind of browser is running. Browser PropertiesJavaScript defines eight properties browsers can report:
Checking your Browser The properties returned are different for each browser and platform.
A small
The above script returns the following:
Putting it to workNow that the returned data is established, conditional The following statement checks the position of the string "
The script's results look like this:
By replacing the two
That will result in an instantaneous transfer to the URL specified. One way of shifting users based on their browsers would be to detect JavaScript enabled users and send them to a different page while the remainder of this page would be plain HTML for those not redirected by the script. Location Location LocationThe
ConclusionsThe basic idea behind browser detection is pretty simple. Based on the concepts above, most any browser detection script can be developed. Most programming is just a collection of simple functions stacked on top of one another. Hope this was helpful. Joe Maller
(this page was salvaged from an incomplete 1996 original) |
Film & VideoRecording the sound of PhotographyProjectsFinal Cut ProDesignWRITINGSite Notes Archive (weblog) Web ResourcesAbout Joe MallerPast Home Pages Etc.Search joemaller.comContact Me
|
|