| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //设备信息
- var getDeviceInfo = function (key) {
- var agent = navigator.userAgent.toLowerCase()
- //获取版本号
- , getVersion = function (label) {
- var exp = new RegExp(label + '/([^\\s\\_\\-]+)');
- label = (agent.match(exp) || [])[1];
- return label || false;
- }
- //返回结果集
- , result = {
- os: function () { //底层操作系统
- if (/windows/.test(agent)) {
- return 'windows';
- } else if (/linux/.test(agent)) {
- return 'linux';
- } else if (/iphone|ipod|ipad|ios/.test(agent)) {
- return 'ios';
- } else if (/mac/.test(agent)) {
- return 'mac';
- }
- }()
- , ie: function () { //ie版本
- return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
- (agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识
- ) : false;
- }()
- , weixin: getVersion('micromessenger') //是否微信
- };
- //任意的key
- if (key && !result[key]) {
- result[key] = getVersion(key);
- }
- //移动设备
- result.android = /android/.test(agent);
- result.ios = result.os === 'ios';
- result.mobile = (result.android || result.ios) ? true : false;
- return result;
- };
- // 浏览器信息
- var getBrowserInfo = function () {
- var agent = navigator.userAgent.toLowerCase();
- var regStr_ie = /msie [\d.]+;/gi;
- var regStr_ff = /firefox\/[\d.]+/gi
- var regStr_chrome = /chrome\/[\d.]+/gi;
- var regStr_saf = /safari\/[\d.]+/gi;
- //IE
- if (agent.indexOf("msie") > 0) {
- return agent.match(regStr_ie);
- }
- //firefox
- if (agent.indexOf("firefox") > 0) {
- return agent.match(regStr_ff);
- }
- //Safari
- if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
- return agent.match(regStr_saf);
- }
- //Chrome
- if (agent.indexOf("chrome") > 0) {
- return agent.match(regStr_chrome);
- }
- }
- var getClientInfo = function() {
- try {
- var deviceInfo = getDeviceInfo();
- var browserInfo = getBrowserInfo();
- deviceInfo.browserInfo = (browserInfo && browserInfo[0]) ? browserInfo[0] : 'unknown';
- return encodeURI(JSON.stringify(deviceInfo));
- } catch (error) {
- return "GetClientInfo Error! msg: " + error;
- }
- }
- ;(function(){
- // 访问统计接口返回 HTML。使用隐藏 iframe 触发服务端记录,避免 script MIME 报错影响页面控制台。
- var bp = document.createElement('iframe');
- bp.style.cssText = 'display:none;width:0;height:0;border:0';
- bp.width = '0';
- bp.height = '0';
- bp.tabIndex = -1;
- bp.setAttribute('aria-hidden', 'true');
- bp.src = '/website/visit/?address=' + encodeURI(location.href) + "&pathname=" + encodeURI(location.pathname) + "&msg=" + getClientInfo();
- if (document.body) {
- document.body.appendChild(bp);
- } else {
- var s = document.getElementsByTagName("script")[0];
- s.parentNode.insertBefore(bp, s);
- }
- })();
|