jquery.client.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. (function() {
  2. var BrowserDetect = {
  3. init: function () {
  4. this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
  5. this.version = this.searchVersion(navigator.userAgent)
  6. || this.searchVersion(navigator.appVersion)
  7. || "an unknown version";
  8. this.OS = this.searchString(this.dataOS) || "an unknown OS";
  9. },
  10. searchString: function (data) {
  11. for (var i=0;i<data.length;i++) {
  12. var dataString = data[i].string;
  13. var dataProp = data[i].prop;
  14. this.versionSearchString = data[i].versionSearch || data[i].identity;
  15. if (dataString) {
  16. if (dataString.indexOf(data[i].subString) != -1)
  17. return data[i].identity;
  18. }
  19. else if (dataProp)
  20. return data[i].identity;
  21. }
  22. },
  23. searchVersion: function (dataString) {
  24. var index = dataString.indexOf(this.versionSearchString);
  25. if (index == -1) return;
  26. return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  27. },
  28. dataBrowser: [
  29. {
  30. string: navigator.userAgent,
  31. subString: "Chrome",
  32. identity: "Chrome"
  33. },
  34. { string: navigator.userAgent,
  35. subString: "OmniWeb",
  36. versionSearch: "OmniWeb/",
  37. identity: "OmniWeb"
  38. },
  39. {
  40. string: navigator.vendor,
  41. subString: "Apple",
  42. identity: "Safari",
  43. versionSearch: "Version"
  44. },
  45. {
  46. prop: window.opera,
  47. identity: "Opera"
  48. },
  49. {
  50. string: navigator.vendor,
  51. subString: "iCab",
  52. identity: "iCab"
  53. },
  54. {
  55. string: navigator.vendor,
  56. subString: "KDE",
  57. identity: "Konqueror"
  58. },
  59. {
  60. string: navigator.userAgent,
  61. subString: "Firefox",
  62. identity: "Firefox"
  63. },
  64. {
  65. string: navigator.vendor,
  66. subString: "Camino",
  67. identity: "Camino"
  68. },
  69. { // for newer Netscapes (6+)
  70. string: navigator.userAgent,
  71. subString: "Netscape",
  72. identity: "Netscape"
  73. },
  74. {
  75. string: navigator.userAgent,
  76. subString: "MSIE",
  77. identity: "Explorer",
  78. versionSearch: "MSIE"
  79. },
  80. {
  81. string: navigator.userAgent,
  82. subString: "Gecko",
  83. identity: "Mozilla",
  84. versionSearch: "rv"
  85. },
  86. { // for older Netscapes (4-)
  87. string: navigator.userAgent,
  88. subString: "Mozilla",
  89. identity: "Netscape",
  90. versionSearch: "Mozilla"
  91. }
  92. ],
  93. dataOS : [
  94. {
  95. string: navigator.platform,
  96. subString: "Win",
  97. identity: "Windows"
  98. },
  99. {
  100. string: navigator.platform,
  101. subString: "Mac",
  102. identity: "Mac"
  103. },
  104. {
  105. string: navigator.userAgent,
  106. subString: "iPhone",
  107. identity: "iPhone/iPod"
  108. },
  109. {
  110. string: navigator.platform,
  111. subString: "Linux",
  112. identity: "Linux"
  113. }
  114. ]
  115. };
  116. BrowserDetect.init();
  117. window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser, browserversion : BrowserDetect.version };
  118. /* window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser };*/
  119. })();