space.website.visit.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //设备信息
  2. var getDeviceInfo = function (key) {
  3. var agent = navigator.userAgent.toLowerCase()
  4. //获取版本号
  5. , getVersion = function (label) {
  6. var exp = new RegExp(label + '/([^\\s\\_\\-]+)');
  7. label = (agent.match(exp) || [])[1];
  8. return label || false;
  9. }
  10. //返回结果集
  11. , result = {
  12. os: function () { //底层操作系统
  13. if (/windows/.test(agent)) {
  14. return 'windows';
  15. } else if (/linux/.test(agent)) {
  16. return 'linux';
  17. } else if (/iphone|ipod|ipad|ios/.test(agent)) {
  18. return 'ios';
  19. } else if (/mac/.test(agent)) {
  20. return 'mac';
  21. }
  22. }()
  23. , ie: function () { //ie版本
  24. return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
  25. (agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识
  26. ) : false;
  27. }()
  28. , weixin: getVersion('micromessenger') //是否微信
  29. };
  30. //任意的key
  31. if (key && !result[key]) {
  32. result[key] = getVersion(key);
  33. }
  34. //移动设备
  35. result.android = /android/.test(agent);
  36. result.ios = result.os === 'ios';
  37. result.mobile = (result.android || result.ios) ? true : false;
  38. return result;
  39. };
  40. // 浏览器信息
  41. var getBrowserInfo = function () {
  42. var agent = navigator.userAgent.toLowerCase();
  43. var regStr_ie = /msie [\d.]+;/gi;
  44. var regStr_ff = /firefox\/[\d.]+/gi
  45. var regStr_chrome = /chrome\/[\d.]+/gi;
  46. var regStr_saf = /safari\/[\d.]+/gi;
  47. //IE
  48. if (agent.indexOf("msie") > 0) {
  49. return agent.match(regStr_ie);
  50. }
  51. //firefox
  52. if (agent.indexOf("firefox") > 0) {
  53. return agent.match(regStr_ff);
  54. }
  55. //Safari
  56. if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
  57. return agent.match(regStr_saf);
  58. }
  59. //Chrome
  60. if (agent.indexOf("chrome") > 0) {
  61. return agent.match(regStr_chrome);
  62. }
  63. }
  64. var getClientInfo = function() {
  65. try {
  66. var deviceInfo = getDeviceInfo();
  67. var browserInfo = getBrowserInfo();
  68. deviceInfo.browserInfo = browserInfo[0];
  69. return encodeURI(JSON.stringify(deviceInfo));
  70. } catch (error) {
  71. return "GetClientInfo Error! msg: " + error;
  72. }
  73. }
  74. ;(function(){
  75. var bp = document.createElement('script');
  76. bp.src = '/website/visit/?address=' + encodeURI(location.href) + "&pathname=" + encodeURI(location.pathname) + "&msg=" + getClientInfo();
  77. var s = document.getElementsByTagName("script")[0];
  78. s.parentNode.insertBefore(bp, s);
  79. })();