ua.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * $Log: ua.js,v $
  3. * Revision 1.1 2005/06/16 08:52:30 jia2612
  4. * *** empty log message ***
  5. *
  6. * Revision 1.1 2005/06/03 01:31:24 jia2612
  7. * *** empty log message ***
  8. *
  9. * Revision 1.1 2005/03/25 03:18:36 linhh
  10. * Eas Portal Origin Version
  11. *
  12. * Revision 1.1 2005/03/21 09:41:26 linhh
  13. * *** empty log message ***
  14. *
  15. * Revision 1.2 2005/03/07 01:23:39 aegeanmist
  16. * *** empty log message ***
  17. *
  18. * Revision 1.1 2005/02/18 06:01:04 linhh
  19. * *** empty log message ***
  20. *
  21. * Revision 1.1 2005/01/25 03:30:30 jia2612
  22. * 在根目录下创建存放公共JS的目录script并添加树控件需要的JS
  23. *
  24. * Revision 1.9 2002/07/22 14:06:21 bc6ix
  25. * fix license path, change version reporting to use 2 digits for each level
  26. *
  27. * Revision 1.8 2002/07/07 08:23:07 bc6ix
  28. * fix line endings
  29. *
  30. * Revision 1.7 2002/05/14 16:52:52 bc6ix
  31. * use CVS Log for revision history
  32. *
  33. *
  34. */
  35. /* ***** BEGIN LICENSE BLOCK *****
  36. * Licensed under Version: MPL 1.1/GPL 2.0/LGPL 2.1
  37. * Full Terms at http://bclary.com/lib/js/license/mpl-tri-license.txt
  38. *
  39. * Software distributed under the License is distributed on an "AS IS" basis,
  40. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  41. * for the specific language governing rights and limitations under the
  42. * License.
  43. *
  44. * The Original Code is Netscape code.
  45. *
  46. * The Initial Developer of the Original Code is
  47. * Netscape Corporation.
  48. * Portions created by the Initial Developer are Copyright (C) 2001
  49. * the Initial Developer. All Rights Reserved.
  50. *
  51. * Contributor(s): Bob Clary <bclary@netscape.com>
  52. *
  53. * ***** END LICENSE BLOCK ***** */
  54. function xbDetectBrowser()
  55. {
  56. var oldOnError = window.onerror;
  57. var element = null;
  58. window.onerror = null;
  59. // work around bug in xpcdom Mozilla 0.9.1
  60. window.saveNavigator = window.navigator;
  61. navigator.OS = '';
  62. navigator.version = parseFloat(navigator.appVersion);
  63. navigator.org = '';
  64. navigator.family = '';
  65. var platform;
  66. if (typeof(window.navigator.platform) != 'undefined')
  67. {
  68. platform = window.navigator.platform.toLowerCase();
  69. if (platform.indexOf('win') != -1)
  70. navigator.OS = 'win';
  71. else if (platform.indexOf('mac') != -1)
  72. navigator.OS = 'mac';
  73. else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
  74. navigator.OS = 'nix';
  75. }
  76. var i = 0;
  77. var ua = window.navigator.userAgent.toLowerCase();
  78. if (ua.indexOf('safari') != -1)
  79. {
  80. i = ua.indexOf('safari');
  81. navigator.family = 'safari';
  82. navigator.org = 'safari';
  83. navigator.version = parseFloat('0' + ua.substr(i+7), 10);
  84. }
  85. else if (ua.indexOf('opera') != -1)
  86. {
  87. i = ua.indexOf('opera');
  88. navigator.family = 'opera';
  89. navigator.org = 'opera';
  90. navigator.version = parseFloat('0' + ua.substr(i+6), 10);
  91. }
  92. else if ((i = ua.indexOf('msie')) != -1)
  93. {
  94. navigator.org = 'microsoft';
  95. navigator.version = parseFloat('0' + ua.substr(i+5), 10);
  96. if (navigator.version < 4)
  97. navigator.family = 'ie3';
  98. else
  99. navigator.family = 'ie4'
  100. }
  101. else if (ua.indexOf('gecko') != -1)
  102. {
  103. navigator.family = 'gecko';
  104. var rvStart = ua.indexOf('rv:');
  105. var rvEnd = ua.indexOf(')', rvStart);
  106. var rv = ua.substring(rvStart+3, rvEnd);
  107. var rvParts = rv.split('.');
  108. var rvValue = 0;
  109. var exp = 1;
  110. for (var i = 0; i < rvParts.length; i++)
  111. {
  112. var val = parseInt(rvParts[i]);
  113. rvValue += val / exp;
  114. exp *= 100;
  115. }
  116. navigator.version = rvValue;
  117. if (ua.indexOf('netscape') != -1)
  118. navigator.org = 'netscape';
  119. else if (ua.indexOf('compuserve') != -1)
  120. navigator.org = 'compuserve';
  121. else
  122. navigator.org = 'mozilla';
  123. }
  124. else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  125. {
  126. var is_major = parseFloat(navigator.appVersion);
  127. if (is_major < 4)
  128. navigator.version = is_major;
  129. else
  130. {
  131. i = ua.lastIndexOf('/')
  132. navigator.version = parseFloat('0' + ua.substr(i+1), 10);
  133. }
  134. navigator.org = 'netscape';
  135. navigator.family = 'nn' + parseInt(navigator.appVersion);
  136. }
  137. else if ((i = ua.indexOf('aol')) != -1 )
  138. {
  139. // aol
  140. navigator.family = 'aol';
  141. navigator.org = 'aol';
  142. navigator.version = parseFloat('0' + ua.substr(i+4), 10);
  143. }
  144. else if ((i = ua.indexOf('hotjava')) != -1 )
  145. {
  146. // hotjava
  147. navigator.family = 'hotjava';
  148. navigator.org = 'sun';
  149. navigator.version = parseFloat(navigator.appVersion);
  150. }
  151. window.onerror = oldOnError;
  152. }
  153. xbDetectBrowser();