前言:
js判断当前是否是企业微信环境,微信环境
封装方法:
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'
}
}使用方法:
const envresult = envjudge()
// 企业微信
if (envresult === 'com-wx-mobile' || envresult === 'com-wx-pc') {
}附:判断是否是微信内置浏览器,区分企业微信和微信
if(/micromessenger/i.test(navigator.useragent)){
alert("微信浏览器");
}else{
alert("请使用微信浏览器打开");
} var ua= window.navigator.useragent.tolowercase();
if( (ua.match(/micromessenger/i) == 'micromessenger') && (ua.match(/wxwork/i) == 'wxwork') ){
console.log("企业微信客户端");
}else if( ua.match(/micromessenger/i) == 'micromessenger' ){
console.log("微信客户端");
}经常要判断是否是微信浏览器打开,如果是的话才进行微信认证/跳转
否则不进行跳转或者使用其他认证
总结
到此这篇关于如何用js判断当前是否是企业微信环境还是微信环境的文章就介绍到这了,更多相关js判断当前微信环境内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论