当前位置:网站首页>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()
边栏推荐
猜你喜欢
Swoole process model diagram
Multithreading advanced level
CompletableFuture从了解到精通,你想知道的这里都有
1.7 - CPU的性能指标
Idea add database
接口中方法详解
Idea run SQL file
Static routing job
Use and principle of completionservice (source code analysis)
Completabilefuture: from understanding to mastering, here are all you want to know
随机推荐
Idea add database
数据读写:Unity中基于C#脚本实现数据读写功能
Common address collection
Variable parameters of go
583. deleting two strings - Dynamic Planning
DXP copper laying settings
Common NPM install errors
Docker is equipped with the latest MySQL image
Who doesn't want a blog site of their own - build a blog site WordPress
Win10 /11 开热点无法上网问题
ES6箭头函数
Verilog中case,casez,casex语句的用法
Several commands not commonly used in MySQL
Base64 explanation: playing with pictures Base64 encoding
从底层结构开始学习FPGA----RAM IP核及关键参数介绍
Rhcsa day 3
Traitement d'images 7 - amélioration d'images
DOM (document object model) document XML file object model
ES6解构赋值
ES6 arrow function