simple functions in javascript to detect browser version

here are some very simple javascript functions, for detecting IE, and which version of IE.

this can be handy, especially with newer versions of jQuery that do not by default support browser detection.

 //simple functions for detecting the browser version:  
 //  
 //ref: http://www.quirksmode.org/js/detect.html  
 var browsers = {  
   isIe: function () {  
     return (navigator.userAgent.indexOf('MSIE ') >= 0);  
   },  
   isIe7: function () {  
     var res = this.isIe() && (navigator.userAgent.indexOf('MSIE 7') >= 0);  
     console.debug('isIe7: ' + res);  
     return res;  
   },  
   isIe8: function () { //note: IE8 will report as IE7, if in compatibility mode  
     var res = this.isIe() && (navigator.userAgent.indexOf('MSIE 8') >= 0);  
     console.debug('isIe8: ' + res);  
     return res;  
   },  
   isIe9: function () { //note: IE9 will report as IE8, if in compatibility mode  
     var res = this.isIe() && (navigator.userAgent.indexOf('MSIE 9') >= 0);  
     console.debug('isIe9: ' + res);  
     return res;  
   }  
 };  

reference: http://www.quirksmode.org/js/detect.html

Comments