当前位置:网站首页>判断h5在两端是在微信环境还是企业微信环境
判断h5在两端是在微信环境还是企业微信环境
2022-06-30 06:18:00 【Front 小思】

前要:今天遇到一个需求,分享过来的链接中对地址在不同端的操作处理!
1、判断H5页面是否在微信/企业微信环境中打开:
var ua = navigator.userAgent.toLowerCase(); // 将用户代理头的值转为小写
判断微信的方法的两种方法:
ua.match(/micromessenger/i) == 'micromessenger'
/micromessenger/i.test(navigator.userAgent); //结果为true或者false
判断企业微信环境的两种方法:
ua.match(/wxwork/i) == 'wxwork'
/wxwork/i.test(navigator.userAgent); //结果为true或者false
2、判断是否为移动端:
window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i); // true:mobile端, false:PC端
3、封装:
function envjudge() {
var isMobile = window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i); // 是否手机端
var isWx = /micromessenger/i.test(navigator.userAgent); // 是否微信
var isComWx = /wxwork/i.test(navigator.userAgent); // 是否企业微信
if (isComWx && isMobile) {
//手机端企业微信
return 'com-wx-mobile'
}
else if (isComWx && !isMobile) {
//PC端企业微信
return 'com-wx-pc'
}
else if (isWx && isMobile) {
// 手机端微信
return 'wx-mobile';
}
else if (isWx && !isMobile) {
// PC端微信
return 'wx-pc';
}
else {
return 'other';
}
}
//调用
envjudge()
边栏推荐
- 圖像處理7-圖像增强
- Set in set (III)
- 1.8 - 多级存储
- New project folder based on PIO plug-in in vscode -- Interpretation
- Record a problem tracking of excessive load
- Who doesn't want a blog site of their own - build a blog site WordPress
- Base64详解:玩转图片Base64编码
- Summary of 2 billion redis data migration
- Prototype and prototype chain in JS
- General contents of learning reinforcement learning
猜你喜欢

【微信小程序:单选、多选样式,背景色,圆角】
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

gazebo/set_ model_ State topic driving UAV model through posture

New project folder based on PIO plug-in in vscode -- Interpretation

CompletableFuture从了解到精通,你想知道的这里都有

Why does the verification code not refresh when clicked

IO streams (common streams)

Zibll sub theme v6.4.1wordpress open source download_ Crack the original / use it directly / no tutorial required

DXP copper laying settings

Traitement d'images 7 - amélioration d'images
随机推荐
Idea add database
A small template (an abstract class, a complete process is written in a method, the uncertain part is written in the abstract method, and then the subclass inherits the abstract class, and the subclas
Control method of UAV formation
SHELL
Switch must be better than if Else fast
C语言:练习题三
583. 两个字符串的删除操作-动态规划
46. full arrangement -dfs double hundred code
文件操作IO-Part1
Rotate dimension tool rolabelimg
Getting started with research
Base64详解:玩转图片Base64编码
[regular expression series] greedy and non greedy patterns
HuaWei满级大牛首次分享出这份598页网络协议全彩手册
ES6 array
Beauty of Refactoring: when multithreaded batch processing task lifts the beam - Universal scaffold
Subnet division and subnet summary
Wuenda coursera deep learning course
Analysis of startup process of gazebo multi computer simulation
Collections tool class (V)