当前位置:网站首页>判断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()
边栏推荐
- Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries
- PHP knowledge points
- uniapp 微信小程序返回上一页并刷新
- Set in set (III)
- File operation io-part1
- 从底层结构开始学习FPGA----RAM IP核及关键参数介绍
- 圖像處理7-圖像增强
- Dynamic routing job
- Data read / write: realize data read / write function based on C # script in unity
- Hao looking for a job
猜你喜欢
Static routing job
深度学习---三好学生各成绩所占权重问题(3)
Unable to access the Internet at win10 /11 hotspot
Use and principle of completionservice (source code analysis)
图片。。。。。
文件操作IO-Part1
Multithreading advanced level
IO streams (common streams)
Balanced binary tree judgment of Li Kou 110 -- classic problems
1.8 - 多级存储
随机推荐
1.9 - 存储器的分类
Summary of 2 billion redis data migration
Use and principle of completionservice (source code analysis)
JS prototype chain object function relationship
Golang's handwritten Web Framework
Collections tool class (V)
Common NPM install errors
To: k210 realizes face recognition (code interpretation attached)
uniapp 微信小程序返回上一页并刷新
反編譯正常回編譯出現問題自己解决辦法
RSA and AES
ES6 deconstruction assignment
圖像處理7-圖像增强
Loading class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb
High performance distributed execution framework ray
When to use redis
Gazebo installation, uninstall and upgrade
DOM (document object model) document XML file object model
Unclear about glide loading picture
Develop stylelint rules from zero (plug-ins)