//獲取url參數 function getUrlParams(name, url) { if (!url) url = location.href; name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regexS = '[ ...
//獲取url參數
function getUrlParams(name, url) {
if (!url) url = location.href;
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regexS = '[\\?&]' + name + '=([^&#]*)';
var regex = new RegExp(regexS);
var results = regex.exec(url);
return results == null ? null : results[1];
}
// 獲取登錄狀態 & 用戶昵稱
function getMUserInfo() { let loggedIn = false; // 是否登錄 let uid = 0; // 用戶ID const cookieClubUserShow = getCookie('getCookie');//要取的欄位 const autouserid = getCookie('getCookie'); // const cookieClubUserShow = '52100122|197|2|%e7%9a%b1%e7%9c%89_|0|0|0|/g11/M04/AB/BA/120X120_0_q87_autohomecar__wKjBzFnkZg6ABBS_AAFIXhsHM1c188.jpg|2018-07-31 19:42:33|0' if (cookieClubUserShow && autouserid) { const clubUserShow = cookieClubUserShow.split('|'); loggedIn = true; [uid] = clubUserShow; } return { loggedIn, uid, }; }
判斷是否是app
function getAppInfo() { const ua = navigator.userAgent; const co = document.cookie; const ur = /auto_(iphone|android)(;|%3B|\/)(\d+\.\d+\.\d+)/i; const cr = /.*app_key=auto_(iphone|android)(.*)app_ver=(\d+\.\d+\.\d+)/i; const match = ua.match(ur) || co.match(cr); return { isApp: /autohomeapp/.test(ua) || ur.test(ua) || cr.test(co), appKey: match && match[1], appVer: match && match[3], }; }
取瀏覽器內核,返回各終端類型
function getBrowser() {
const ua = navigator.userAgent
return {
trident: ua.indexOf('Trident') > -1, // IE內核
presto: ua.indexOf('Presto') > -1, // opera內核
webKit: ua.indexOf('AppleWebKit') > -1, // 蘋果、谷歌內核
gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1, // 火狐內核
mobile: !!ua.match(/AppleWebKit.*Mobile.*/), // 是否為移動終端
ios: !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), // ios終端
android: ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1, // android終端
iPhone: ua.indexOf('iPhone') > -1, // 是否為iPhone或者QQHD瀏覽器
iPad: ua.indexOf('iPad') > -1, // 是否iPad
webApp: ua.indexOf('Safari') === -1, // 是否web應該程式,沒有頭部與底部
weixin: ua.indexOf('MicroMessenger') > -1, // 是否微信 (2015-01-22新增)
qq: ua.match(/\sQQ/i) === ' qq', // 是否QQ
escApp: ua.indexOf('UsedCar') > -1, // 二手車APP
autohome: ua.indexOf('autohomeapp') > -1
}
}