R
E
S
O
U
R
C
E
S
       Question Index      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: side or top popup menus, buttons, image rotators, navbars, tons more.
_______________________

Send us your questions and wittiest comments.
_______________________

Report errors on our site.
_______________________

Share your neatest DHTML examples with us; we may publish them.
_______________________


_______________________

      QUESTION INDEX      

Question Index
Browser Insanity
JavaScript
Animation
Buttons and Menus
CSS and HTML


  INFORMATIVE ARTICLES  

Menus-and-Buttons-
Part-I.htm


Menus-and-Buttons-
Part-II.htm


Change-Div-Size-Color-
and-Location-with-the-
W3C-DOM.htm


Bouncing-Ball-Animation-
with-the-W3C-DOM.htm


Style-Changes-with-the-
W3C-DOM.htm


Animation-with-the-
W3C-DOM.htm


Window-Play-and-Some-
Important-DOM-Methods.htm


Using-getElementsByTagName
-and-getElementsByName.htm


The-CSS-Resources-Intro-
Page.htm


Convert-Word-Files-to-HTML-
and-Install-Editor2-to-
Use-Instead-of-NotePad.htm


CSS-Issues.htm

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)