王新阳

wangxinyang

怎么判断是否在微信浏览器中打开

方法一:

<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
// 判断是否在微信中打开
if (typeof WeixinJSBridge === 'object' && typeof WeixinJSBridge.invoke === 'function') {
    console.log('当前页面在微信中打开');
} else {
    console.log('当前页面不在微信中打开');
}

方法二:

function is_weixn(){
    var ua=navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger"){
        return true;
    }else{
        return false;
    }
}
2025-01-25
2025-02-05 星期三 农历正月初八