1. WeChat
Determine whether the current browser is WeChat by judging whether navigator.userAgent.toLowerCase()
contains the field.micromessenger
// 方法1
function judge() {
const ua = navigator.userAgent.toLowerCase()
return ua.match(/MicroMessenger/i) == 'micromessenger' // true or false
}
// 方法2
function judge() {
const ua = navigator.userAgent.toLowerCase()
return ua.indexOf('micromessenger') !== -1 // true or false
}
// 方法3
function judge() {
const ua = navigator.userAgent.toLowerCase()
return ua.includes('micromessenger') // true or false
}
Two, DingTalk
Determine whether the current browser is DingTalk by judging whether window.navigator.userAgen
contains the field.DingTalk
// 方法1
function judge() {
const ua = window.navigator.userAgent
return ua.match(/MicroMessenger/i) == 'DingTalk' // true or false
}
// 方法2
function judge() {
const ua = window.navigator.userAgent
return ua.indexOf('DingTalk') !== -1 // true or false
}
// 方法3
function judge() {
const ua = window.navigator.userAgent
return ua.includes('DingTalk') // true or false
}