| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //设备信息
- 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[0];
- return encodeURI(JSON.stringify(deviceInfo));
- } catch (error) {
- return "GetClientInfo Error! msg: " + error;
- }
- }
- ;(function(){
- var bp = document.createElement('script');
- bp.src = '/website/visit/?address=' + encodeURI(location.href) + "&pathname=" + encodeURI(location.pathname) + "&msg=" + getClientInfo();
- var s = document.getElementsByTagName("script")[0];
- s.parentNode.insertBefore(bp, s);
- })();
|