JavaScript 限制只能在微信浏览器中打开

思路:1、限制在微信浏览器打开。2、判断页面是否是在微信浏览器打开。3、对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器function is_weixin(){va

思路:1、限制在微信浏览器打开。2、判断页面是否是在微信浏览器打开。3、对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
function is_weixin(){
    var ua = navigator.userAgent.toLowerCase(); //判断浏览器的类型
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
if (!is_weixin()) { // 如果不是微信内置浏览器,就动态跳转到以下页面
    window.location.href = 'https://open.weixin.qq/connect/oauth2/authorize?appid=wxdf3f22ebfe96b912&redirect_uri=xxx&response_type=code&scope=snsapi_base&state=hyxt#wechat_redirect';//不是就跳转提示页面
}else{
    window.location.href = 'index.html'//是微信浏览器就跳转index.html文件
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/web/1741132993a4312479.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信