当前位置:网站首页>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()
边栏推荐
猜你喜欢

Who doesn't want a blog site of their own - build a blog site WordPress
![[wechat applet: single or multiple styles, background color, rounded corners]](/img/01/0381915591b0d3c13afbba4d50952d.png)
[wechat applet: single or multiple styles, background color, rounded corners]

1.9 - 存储器的分类

Verilog中case,casez,casex语句的用法

1.8 - 多级存储

IO streams (common streams)
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Idea run SQL file

观察者模式、状态模式在实际工作中的使用

IP TCP UDP network encryption suite format
随机推荐
Pycharm shortcut key
Idea add database
01. 正则表达式概述
Uniapp wechat applet returns to the previous page and refreshes
Jgaurora A8 configuration file
Es6数组
HCIA day 1
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
Four ways to create multithreads
Getting started with research
DOM (document object model) document XML file object model
583. deleting two strings - Dynamic Planning
Feisheng: Based on the Chinese word breaker ik-2 ways to build custom hot word separators Showcase & pit arrangement Showtime
文件操作IO-Part1
2020-10-06
Ini parsing learning documents
Basic use of markdown
Usage of case, casez and casex statements in Verilog
Common NPM install errors
Altium designer creates multiple class networks to realize different lineweights of multiple networks