jsGuru.com
HomeIntroductionFundamentalsCompatibilityResourcesComments   Browser Sniffing -
Functionality Method
 
Be honest! Do you really care whether the reader is using Internet Explorer version 4.51 on a Mac or Netscape Navigator version 4.04 on a Windows machine? Probably not. More likely you want to know if the reader's browser supports image swapping so you can do those cool rollover buttons. Or you want to know if the reader's browser supports style sheets. You might even want to know if the reader's browser does automatic re-flowing of page content so you don't have to do a page reload. Right? Well, why not ask that in the first place instead of doing all the work of checking browser type, version and platform?
    That is the basis of browser sniffing by the javaScript functionality method. You simply ask the reader's browser if a particular kind of functionality is supported.
    Suppose you want to know if a browser supports image swapping. Digging a little deeper, you find out that this functionality is supported only if the browser supports the "images" object. Thus, the following code can be used:
 
 
   
var bUseImageSwapping = (document.images) ? true : false;
 
 
   

 
 
     
   
There are quite a number of such tests you can make. The following table shows some of the more common ones:
 
 
   
var bUseLayers = (document.layers) ? true : false;
var bUseAllCollection = (document.all) ? true : false;
var bUseCSS = bUseLayers || bUseAllCollection;
var bUseDHTML = bUseLayers || bUseAllCollection;
 
 
   
Well, that was certainly easy. The question now is, how do they work? Go on to the next page to find out.
 
Continue
 
       
    © 1999 bnsDesigns