用js限制网页只在微信浏览器中打开
js代码一
$(function(){
//判断页面是否是在微信浏览器打开
//对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
var useragent = navigator.userAgent;
if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
window.location.href = "wxError.html";//若不是微信浏览器,跳转到温馨error页面
}
})
代码二 写成函数方便引用
function getIsWxClient () {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
}
return false;
};
代码三 微信自己写的的代码
window.isInWeixinApp = function() {
return /MicroMessenger/.test(navigator.userAgent);
};
页面
一般情况下限制页面被pc端访问就可以了,那么就可以参考下面的代码了
在需要被pc端访问的页面的脚本里加上如下代码即可:
再附一个各大网站常用的代码
var browser = {
versions : function () {
var u = navigator.userAgent,
app = navigator.appVersion;
return {
trident : u.indexOf('Trident') > -1,
presto : u.indexOf('Presto') > -1,
webKit : u.indexOf('AppleWebKit') > -1,
gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
ios : !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/),
android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,
iPad : u.indexOf('iPad') > -1,
webApp : u.indexOf('Safari') == -1,
QQbrw : u.indexOf('MQQBrowser') > -1,
UCbrw : u.indexOf('UCBrowser') > -1,
weiXin : u.indexOf('MicroMessenger') > -1,
ucLowEnd : u.indexOf('UCWEB7.') > -1,
ucSpecial : u.indexOf('rv:1.2.3.4') > -1,
ucweb : function () {
try {
return parseFloat(u.match(/ucwebd+.d+/gi).toString().match(/d+.d+/).toString()) >= 8.2
} catch (e) {
if (u.indexOf('UC') > -1) {
return true;
} else {
return false;
}
}
}
(),
Symbian : u.indexOf('Symbian') > -1,
ucSB : u.indexOf('Firefox/1.') > -1
};
}
()
}
到这里就完美了,考高分网小编专门从电影网站扒的代码。



