The Simplest Effective Browser Sniffer
ALL OF THE FOLLOWING JAVASCRIPT ABOUT BROWSER DETECTION SEEMS TO WORK ON JUST ABOUT ALL PLATFORMS AND JUST ABOUT ALL BROWSERS, AS LONG AS JAVASCRIPT IS TURNED ON. Note: I chose to only test for Safari and IE on the Mac, so figure it's Mac Firefox if it isn't Mac IE or Mac Safari but it is Mac. The Netscape/Firefox/Mozilla test is all one variable: Netscape. There's no use testing for Netscape, Mozilla, or Firefox on the Mac since Safari tests erroneously indicate true for the Netscape tests—why Safari wants to be seen as Netscape is anyone's guess, and my guess is that with primitive sniffers that see only IE and Netscape/Firefox/Mozilla, the non-IE Mac browsers are a lot more likely to display well with Netscape-browser-targeted code than IE code. (This would be Apple's way of dealing with the "who cares about little old Mac?" webmasters.) I leave out Konqueror or other minor browsers since they need to either have the good sense to be detected as one of the main browser types like IE or Netscape/Firefox/Mozilla or get out of the browser game. It's true that various tricks can be played to create false browser sniffing results, so these tests are not infallible, but the trouble with object detection is that the browser may begin supporting this object, which makes such tests go awry. However, window.opera and document.all seem like safe bets for object detection for a long time to come.
mactest=(navigator.userAgent.indexOf("Mac")!=-1) //My browser sniffers
Netscape=(navigator.appName.indexOf("Netscape") != -1)
msafari=(navigator.userAgent.indexOf("Safari")!= -1)
wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0}
is_opera = 0; if(window.opera){is_opera=1}
is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1}
if(is_ie&&mactest){is_ie_mac=1}
alert("mactest:"+mactest+", Netscape:"+Netscape+", wsafari:"+wsafari+", msafari:"+msafari+", is_ie:"+is_ie+", is_ie_mac:"+is_ie_mac+", is_opera:"+is_opera)


