獲取url引數(直接取?后邊的引數)
function getUrlQuerys() {
const queryStr = location.search.length ? location.search.substring(1) : '';
const queryArr = queryStr.length ? queryStr.split('&') : [];
let querys = {};
queryArr.forEach(item => {
let temp = item.split('=');
querys[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
});
return querys;
}
const urlQuery = getUrlQuerys();
console.log(urlQuery['urlName'])
//獲取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
}
}
// 打開彈框,頁面禁止滾動
var scrollDistence = 0;
function noScroll() {
scrollDistence = $(window).scrollTop();
$('body').css({
overflow: 'hidden',
position: 'fixed',
width: '100%',
top: 0,
});
}
// 關閉彈框,頁面正常顯示
function canScroll() {
$('body').css({
overflow: '',
position: 'static',
width: 'auto',
top: 0,
});
$(window).scrollTop(scrollDistence);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/148161.html
標籤:JavaScript
上一篇:判斷用戶的瀏覽設備
下一篇:cookie的設定與取值
