Posted By

cmwhitehead on 03/03/10


Tagged


Versions (?)

Browser and OS Authentication Object


 / Published in: JavaScript
 

  1. function AuthObject() {
  2.  
  3. var i, rvN;
  4. var UA = navigator.userAgent.toLowerCase();
  5.  
  6. this.ua = navigator.userAgent.toLowerCase(); // UserAgent in lowserCase
  7. this.isIE = false; // Is it Internet Explorer?
  8. this.isIE8 = false; // Is it Internet Explorer 8?
  9. this.isIE6 = false; // Is it Internet Explorer 6?
  10. this.isFF = false; // Is it Firfox?
  11. this.isSafari = false; // Is it Safari?
  12. this.isChrome = false; // Is it Chrome?
  13. this.isKonqueror = false; // Is it Konqueror?
  14. this.isOpera = false; // Is it Opera?
  15. this.isCamino = false; // Is it Camino? (A gecko-based browser on the Mac)
  16. this.isNav4 = false; // Is it Netscape Navigator 4?
  17. this.isGecko = false; // Is it a Gecko-based browser? (Mozilla Suite, Mozilla Firefox, Netscape 6+)
  18. this.ieVersion = null; // Internet Explorer version
  19. this.ffVersion = null; // Firefox Version
  20. this.operaVersion = null; // Opera Version
  21. this.webkitVersion = null; // WebKit Version
  22. this.geckoRevision = null; // Gecko revision
  23. this.geckoDate = null; // Gecko build date
  24. this.geckoRevisionMajor = null; // Gecko revision major version
  25. this.geckoRevisionMinor = null; // Gecko revision minor version
  26. this.isWin = false; // Is it Windows?
  27. this.isWinVista = false; // Is it Windows Vista?
  28. this.isMac = false; // Is it Mac?
  29. this.isLinux = false; // Is it Linux?
  30.  
  31.  
  32. //BROWSER AUTHENTICATION
  33. if(UA.indexOf("msie") >= 0){
  34. this.isIE = true;}
  35.  
  36. if((UA.indexOf('trident/4')>=0)||(UA.indexOf('msie 8')>=0)){
  37. this.isIE8 = true;}
  38.  
  39. if(UA.indexOf('msie 6')>=0){
  40. this.isIE6 = true;}
  41.  
  42. if(UA.indexOf("firefox") >= 0){
  43. this.isFF = true;}
  44.  
  45. if(UA.indexOf("safari") >= 0 && UA.indexOf("applewebkit") >=0 && UA.indexOf("version") >= 0){
  46. this.isSafari = true;}
  47.  
  48. if(UA.indexOf("chrome") >= 0 && UA.indexOf("applewebkit") >= 0 && UA.indexOf("safari")){
  49. this.isChrome = true;}
  50.  
  51. if(UA.indexOf("konqueror") >= 0){
  52. this.isKonqueror = true;}
  53.  
  54. if(UA.indexOf("opera") >= 0){
  55. this.isOpera = true;}
  56.  
  57. if(UA.indexOf("camino") >= 0){
  58. this.isCamino = true;}
  59.  
  60. if(UA.indexOf('mozilla')>=0 && UA.indexOf('compatible')==-1 && parseInt(navigator.appVersion)<5) {
  61. this.isNav4 = true;}
  62.  
  63. if(UA.indexOf("gecko/") >= 0){
  64. this.isGecko = true;}
  65.  
  66. if(this.isIE){
  67. this.ieVersion=UA.substr(UA.indexOf('msie')+5,3);}
  68.  
  69. if(this.isOpera){
  70. this.operaVersion=UA.substr(UA.indexOf('opera')+6,4);}
  71.  
  72. if(UA.indexOf("applewebkit/") >= 0){
  73. i = UA.indexOf("applewebkit/");
  74. this.webkitVersion = parseFloat(UA.substr(i + 12));}
  75.  
  76. if(UA.indexOf("firefox/") >= 0){
  77. i = UA.indexOf("firefox/");
  78. this.ffVersion = parseFloat(UA.substr(i + 8)) ;}
  79.  
  80. rvN = "rv:";
  81. if(this.isGecko){
  82. i = UA.indexOf(rvN)
  83. var geckoRevisionStr = UA.substr(i + rvN.length);
  84. this.geckoRevision=parseFloat(UA.substr(i + rvN.length));
  85. this.geckoDate=parseFloat(UA.substr(UA.indexOf("gecko/")+6));
  86. this.geckoRevisionMajor=parseFloat(geckoRevisionStr.split("."));
  87. this.geckoRevisionMinor=parseFloat(geckoRevisionStr.split(".")[1]+ "."+geckoRevisionStr.split(".")[2]);}
  88.  
  89. //OS AUTHENTICATION
  90. if(UA.indexOf("windows") >= 0 && UA.indexOf("windows nt 6.0") <= 0){
  91. this.isWin = true;}
  92.  
  93. if(UA.indexOf("windows nt 6.0") >=0){
  94. this.isWinVista = true;}
  95.  
  96. if(UA.indexOf("mac") >=0){
  97. this.isMac = true;}
  98.  
  99. if(UA.indexOf('linux')>=0){
  100. this.isLinux = true;}
  101.  
  102. }
  103.  
  104. var Auth = new AuthObject();

Report this snippet  

You need to login to post a comment.