根据userAgent判断浏览器类型,移动端,PC端,微信,QQ和微博
var os = function () { var ua = navigator.userAgent.toLowerCase(), isAndroid = /(?:android)/.test(ua), isWeChat = /(?:micromessenger)/.test(ua), isQQ = /(?:qq)/.test(ua), isWeiBo = /(?:weibo)/.test(ua), isTablet = /(?:ipad|playbook)/.test(ua) || (isAndroid && !/(?:mobile)/.test(ua)), isPhone = /(?:iphone)/.test(ua) && !isTablet, isPc = !isPhone && !isAndroid && !isTablet; return { isTablet: isTablet,// 平板 isPhone: isPhone, // 苹果 isAndroid: isAndroid, //安卓 isWeChat: isWeChat, //微信 isQQ: isQQ, // QQ isWeiBo: isWeiBo, // 微博 isPc: isPc // PC端 };}();
//使用if (os.isPc) { console.log(‘isPc :‘);} else if (os.isAndroid) { console.log(‘isAndroid‘);}else if (os.isPhone) { console.log(‘isPhone‘);}
end !
时间: 2024-10-09 23:18:50