[Zope] Detecting Mozilla based browsers

Passin, Tom tpassin@mitretek.org
Mon, 31 Mar 2003 17:50:56 -0500


[Gilles Lenfant]

> I'm trying to detect (server side) Mozilla+Midas compatible browsers.
> Since this feature (Midas) is new, finding "Gecko" in the user agent
> signature doesn't seem to be enough.
>=20
> Any clue ? Does it need a Javascript helper ?
>=20

IE does not use the name "cssRules" as per the DOM Rec, while Moz does.
You can discover this somewhat as follows -

var stylesheet=3Ddocument.styleSheets[0]
var rules=3Dstylesheet.rules
var UA
if (rules) { // Must be IE
   UA =3D 'IE'
}
else {
   rules =3D stylesheet.cssRules
   if (rules) { // Correct DOM name - probably Moz
      UA =3D 'Moz'
   }
}

For this to work, there must be a css stylesheet in the document, or
document.stylesSheets[0] will fail.

Now it may happen that some other browser would pass this test, so you
would want to try several such tests.  One possibility is the
XMLHTTPREQUEST object, which exists in both browsers but gets
instantiated differently - see

http://jibbering.com/2002/4/httprequest.html

Cheers,

Tom P