jquery.browser.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. $.browser = {
  2. init: function () {
  3. this.name = this.searchString(this.dataBrowser) || "Other";
  4. this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "Unknown";
  5. },
  6. searchString: function (data) {
  7. for (var i = 0; i < data.length; i++) {
  8. var dataString = data[i].string;
  9. this.versionSearchString = data[i].subString;
  10. if (dataString.indexOf(data[i].subString) !== -1) {
  11. return data[i].identity;
  12. }
  13. }
  14. },
  15. searchVersion: function (dataString) {
  16. var index = dataString.indexOf(this.versionSearchString);
  17. if (index === -1) {
  18. return;
  19. }
  20. var rv = dataString.indexOf("rv:");
  21. if (this.versionSearchString === "Trident" && rv !== -1) {
  22. return parseFloat(dataString.substring(rv + 3));
  23. } else {
  24. return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
  25. }
  26. },
  27. dataBrowser: [
  28. {string: navigator.userAgent, subString: "Chrome", identity: "Chrome"},
  29. {string: navigator.userAgent, subString: "MSIE", identity: "Explorer"},
  30. {string: navigator.userAgent, subString: "Trident", identity: "Explorer"},
  31. {string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
  32. {string: navigator.userAgent, subString: "Safari", identity: "Safari"},
  33. {string: navigator.userAgent, subString: "Opera", identity: "Opera"}
  34. ]
  35. };
  36. $.browser.init();