uniapp超全user-agent判断 包括微信开发工具 hbuilder mac windows 安卓ios端及本地识别

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
}
相关推荐
SoraLuna37 分钟前
「Mac玩转仓颉内测版7」入门篇7 - Cangjie控制结构(下)
算法·macos·动态规划·cangjie
Algorithm15762 小时前
mac上使用docker搭建gitlab
macos·docker·gitlab
余清歌2 小时前
macOS解决U盘装完系统容量变小的问题
macos
SoraLuna2 小时前
「Mac玩转仓颉内测版8」入门篇8 - Cangjie函数与方法
算法·macos·cangjie
zhlx28352 小时前
【免越狱】iOS砸壳 可下载AppStore任意版本 旧版本IPA下载
macos·ios·cocoa
染指11103 小时前
45.第二阶段x86游戏实战2-hook监控实时抓取游戏lua
汇编·c++·windows·反游戏外挂·游戏逆向
Mac分享吧3 小时前
【iStat Menus for MacBook状态栏菜单系统监控工具--安装教程【简单操作,随时了解电脑情况】
macos·mac·istat menus·软件分享·系统数据监控
_处女座程序员的日常7 小时前
Rollup failed to resolve import “destr“ from ***/node_modules/pinia-plugin-pers
javascript·uni-app·vue
牛奔14 小时前
解决Mac M芯片 Wireshark 运行rvictl -s 后,出现Starting device failed
网络·测试工具·macos·wireshark
AirDroid_cn15 小时前
三星手机投屏到MacBook的方法,多台手机同屏展示
macos·智能手机·投屏·手机投屏·三星