• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 18. navigator > Example: Browser Sniffing, the Correct Way

Example: Browser Sniffing, the Correct Way

Earlier in this chapter, I ranted quite a bit about using object detection to identify a browser. The navigator object provides 95 percent of what a JavaScript needs to identify a browser accurately. Here I include a script to identify the browser fairly accurately. Keep in mind this only works on current browsers, as newer versions keep coming out I'm sure this script will have to be adapted to handle the spoofing. Also even in the extensive script later in this chapter a lot of assumptions were made. For instance, Internet Explorer 5.5 is associated with JavaScript 1.3, when JavaScript 1.5 might be more appropriate.

Although this chapter probably sounds like it discourages use of object detection, that is not the intent. Object detection has its uses, but detecting a single object when you need to identify a specific browser is a really bad idea. However, in many cases you really don't care about the “exact” browser the user is using. You only need to know if a certain method or property is supported so that your script will work. In those cases object detection makes a lot more sense than using the massive script that follows.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint