当前位置:网站首页>Judge whether H5 is in wechat environment or enterprise wechat environment at both ends
Judge whether H5 is in wechat environment or enterprise wechat environment at both ends
2022-06-30 06:28:00 【Front thought】

Before : There's a need today , The operation and processing of addresses at different ends in the shared links !
1、 Judge H5 Whether the page is on wechat / Open in the enterprise wechat environment :
var ua = navigator.userAgent.toLowerCase(); // Change the value of the user agent header to lowercase
There are two ways to judge wechat :
ua.match(/micromessenger/i) == 'micromessenger'
/micromessenger/i.test(navigator.userAgent); // The result is true perhaps false
There are two ways to judge the wechat environment of enterprises :
ua.match(/wxwork/i) == 'wxwork'
/wxwork/i.test(navigator.userAgent); // The result is true perhaps false
2、 Judge whether it is a mobile terminal :
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 End , false:PC End
3、 encapsulation :
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); // Whether the mobile terminal
var isWx = /micromessenger/i.test(navigator.userAgent); // Wechat or not
var isComWx = /wxwork/i.test(navigator.userAgent); // Is it enterprise wechat
if (isComWx && isMobile) {
// Mobile enterprise wechat
return 'com-wx-mobile'
}
else if (isComWx && !isMobile) {
//PC End enterprise wechat
return 'com-wx-pc'
}
else if (isWx && isMobile) {
// Mobile wechat
return 'wx-mobile';
}
else if (isWx && !isMobile) {
// PC End wechat
return 'wx-pc';
}
else {
return 'other';
}
}
// call
envjudge()
边栏推荐
- Traitement d'images 7 - amélioration d'images
- ES6 array
- When to use redis
- Unclear about glide loading picture
- General contents of learning reinforcement learning
- Application of redis client list in practice
- Subnet division and subnet summary
- Learn fpga---ram IP core and key parameters from the bottom structure
- A complete performance test process
- ES6 extended operator (...)
猜你喜欢
随机推荐
Vscode configuration proxy
我做功能测试这么多年的心得
Spin official tutorial
01. 正则表达式概述
接口中方法详解
General contents of learning reinforcement learning
01. regular expression overview
File operation io-part1
When to use redis
Mariadb数据库的安装与初始化
Master slave synchronization of MySQL database to realize read-write separation
ES6 deconstruction assignment
Basic use of markdown
Picture.....
RSA and AES
Subnet division and subnet summary
Gazebo model modification
List in set (2)
关于Glide加载图片模糊不清楚
ES6扩展运算符(...)








