uniapp里能够识别钉钉 微信小程序 微信开发工具 hbuilder mac windows 安卓ios端 微博 qq的ua
js
// platform.js
let $platform="H5";
// #ifdef H5
const ua = window.navigator.userAgent.toLowerCase();
const isWxDevtools = ua.match(/wechatdevtools/i) == 'wechatdevtools';
const isWxH5 = ua.match(/micromessenger/i) == 'micromessenger';
$platform = isWxH5||isWxDevtools ? "WXH5" : "H5"
// #endif
// #ifdef MP-WEIXIN
$platform = "MP-WEIXIN"
// #endif
// #ifdef APP
$platform = "APP"
// #endif
export default $platform;
js
//ua.js
import $platform from '@/utils/platform.js';
let ua ="";
// #ifdef H5
ua = window.navigator.userAgent.toLowerCase();
// #endif
const isHbuilderx = ua.includes('hbuilderx'); //hb
const isLocal = (() => {
if ($platform === 'WXH5' || $platform === 'H5') {
return location.hostname === 'localhost' || location.hostname.startsWith('192.168.') || location.hostname
.startsWith('127.0.0.1');
} else {
return false;
}
})();
const isWx = ua.includes('micromessenger'); //微信
const isWxDevtools = ua.includes('wechatdevtools'); //微信开发工具
const isWxH5 = isWx || isWxDevtools; //微信h5
const isMacWx = ua.includes('macwechat'); //mac微信
const isWinWx = ua.includes('windowswechat'); //windows微信
const isPcWechat = isWx && (isMacWx || isWinWx); //pc微信
const isWxMini = ua.includes('miniprogram'); //微信小程序
const isDingtalk = ua.includes('dingtalk'); //钉钉
const isSafari = ua.includes('safari'); //safari
const isFirefox = ua.includes('firefox'); //火狐
const isWeibo = ua.includes('weibo'); //微博
const isQQ = ua.includes('qq'); //qq
const isIphone = ua.includes('iphone'); //iphone
const isIpad = ua.includes('ipad'); //ipad
const isAndroid = ua.includes('android'); //安卓
const isIE = ua.includes('msie') || ua.includes('trident'); //ie
export default {
isWxH5,
isLocal,
isWx,
isMacWx,
isWinWx,
isPcWechat,
isWxMini,
isDingtalk,
isSafari,
isFirefox,
isWeibo,
isQQ,
isIphone,
isIpad,
isAndroid,
isWxDevtools,
isIE,
isHbuilderx
}