当前位置:网站首页>判断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()
边栏推荐
- Beauty of Refactoring: when multithreaded batch processing task lifts the beam - Universal scaffold
- Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries
- Arrangement of in-depth learning materials
- IP TCP UDP network encryption suite format
- Variable parameters of go
- How does Altium designer hide some temporarily unnecessary classes, such as GND
- Image processing 7- image enhancement
- MySQL summary
- Px4 control mode summary
- INI analyse les documents d'apprentissage
猜你喜欢

Gazebo installation, uninstall and upgrade

【微信小程序:单选、多选样式,背景色,圆角】

1.8 - 多级存储

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

Zibll子比主题V6.4.1wordpress 开心版源码下载_破解原版/直接使用/无需教程

IO streams (common streams)

Installation and initialization of MariaDB database

Static routing job

Loading class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb

Unclear about glide loading picture
随机推荐
DXP copper laying settings
Use and principle of completionservice (source code analysis)
ES6数组遍历与ES5数组遍历
Notes of the first week of 2021 Chengdu Arts and Sciences cloud computing intensive training class
How does Altium designer hide some temporarily unnecessary classes, such as GND
As function memo
There is a group of students' score {99, 85, 82, 63, 60}. To add a student's score, insert it into the score sequence and keep the descending order
Cocos studio3.1 installation package win
Picture.....
Record a problem tracking of excessive load
Usage of case, casez and casex statements in Verilog
Dynamic routing job
CompletableFuture从了解到精通,你想知道的这里都有
Learn fpga---ram IP core and key parameters from the bottom structure
Inner member of class 5: inner class
多线程进阶篇
Unclear about glide loading picture
Wechat applet mall project
Uniapp wechat applet returns to the previous page and refreshes
How to use unmarshaljson