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
}
相关推荐
mywpython29 分钟前
mac 最新的chrome版本配置selenium的方式
chrome·python·selenium·macos
耶啵奶膘2 小时前
uni-app:firstUI框架的选择器Select改造,添加一个搜索的插槽
前端·uni-app
sukalot3 小时前
Windows 图形显示驱动开发-WDDM 2.4功能-GPU 半虚拟化(三)
windows·驱动开发
一道微光3 小时前
mac air m系列arm架构芯片安装虚拟机 UTM+debian 浏览器firefox和chrome
arm开发·macos·架构
打工人你好7 小时前
libimobiledevice项目中各个库的作用
macos·objective-c·cocoa
1alisa12 小时前
Sublime Text for Mac v4【注册汉化版】代码编辑器
macos·编辑器·sublime text
qq_3680196616 小时前
Mac下Ollama安装与设置:开启本地大模型之旅
macos
程序猿看视界17 小时前
Uni-app页面信息与元素影响解析
uni-app·状态栏·安全区域·窗口信息·像素比
清晨細雨17 小时前
UniApp集成极光推送详细教程
android·ios·uni-app·极光推送
_未知_开摆17 小时前
uniapp APP端在线升级(简版)
开发语言·前端·javascript·vue.js·uni-app