| | | FAQ server |  |
| Posted: Sat Sep 06, 2008 9:00 pm Post subject: FAQ Topic - How do I detect Opera/Netscape/IE? (2008-09-07) |  |
| |  | |
----------------------------------------------------------------------- FAQ Topic - How do I detect Opera/Netscape/IE? -----------------------------------------------------------------------
The ` navigator ` object contains strings which specify the browser and version; however, this is in general not very genuine. Mozilla (and therefore Netscape 6+) allows this to be freely set, and Opera and IE allow it to be modified. There are also at least 25 other javascript capable browsers with their own strings here.
Generally though, you don't need to identify which browser is being used. There are alternative techniques, but which one you choose depends on why you want to redirect browsers. If it's to offer different CSS stylesheets, then
LINK
shows many techniques. For Scripting, _object_ detection is a better method to use.
LINK
It is also known as feature detection.
Object/feature detection means checking that the object you wish to use is supported by the browser before using it. This means that you don't need to know what browsers support what methods, and your code will automatically be usable on any browser that can execute it.
if (document.getElementById && document.getElementById('el') && document.getElementById('el').style ) { // We know that this browser supports getElementByID and has // a style object, so we can set a style property. document.getElementById('el').style.color="red"; }
Browser bugs can often be detected and overcome in similar ways.
LINK
LINK
LINK
-- Postings such as this are automatically sent once a day. Their goal is to answer repeated questions, and to offer the content to the community for continuous evaluation/improvement. The complete comp.lang.javascript FAQ is at LINK The FAQ workers are a group of volunteers. The sendings of these daily posts are proficiently hosted by LINK |
|