jsGuru.com
HomeIntroductionFundamentalsCompatibilityResourcesComments   Browser Sniffing -
Functionality Method
 
On the last page we saw some examples of browser sniffing using the javaScript functionality method. Now to find out how they work. The answer is quite simple and is an inherent characteristic of javaScript.
    Whenever you test for the existance of an element that does not exist, either because it is not part or the javaScript language or has not been declared, javaScript returns either the null or undefined value. When done in a test statement, javaScript is smart enough to convert this to a zero which, as you know, is the binary representation of false and therefore the test result is false. On the other hand, if the element does exist, the javaScript either returns its type, for instance [object] or its value. In either event, these results do not convert to false and must therefore be true.
    You can see this for yourself in the following simple examples:
 
 
   
var bTest1 = (document.test);
 
 
   

 
 
   
var bTest1 = (document.test) ? true : false;
 
 
   

 
 
     
   
Notice that in the first case, the result is undefined but in the second case, undefined is converted to the boolean false and thus the result is false.
    Generally, I use this method much more than the B/V/P method; it's simpler and in most cases works just as well.
    Now that we have looked at what can be done on the client side with javaScript, let's go on to see what can be done on the server side.
 
Continue
 
       
    © 1999 bnsDesigns