最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

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

业界 admin 10浏览 0评论
思路: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文件
    }
}
思路: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文件
    }
}
发布评论

评论列表 (0)

  1. 暂无评论