你的位置:
首页
>
业界
>
JavaScript 限制只能在微信浏览器中打开
思路: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文件
}
}