//以下是限制只能在微信内置浏览器访问
var useragent = navigator.userAgent;
if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
// 这里警告框会阻塞当前页面继续加载
alert('请使用微信访问!');
// 以下代码是用javascript强行关闭当前页面
var opened = window.open('about:blank', '_self');
opened.opener = null;
opened.close();
}
//以下是限制只能在手机上访问
var system = {};
var p = navigator.platform;
var u = navigator.userAgent;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if (system.win || system.mac || system.xll) {//如果是PC转
if (u.indexOf('Windows Phone') > -1) { //win手机端
}
else {
window.location.href = "http://weixin.sogou.com";
}
}
}
限制只能PC端访问
<script type="text/javascript">
//平台、设备和操作系统
var system ={
win : false,
mac : false,
xll : false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){
}else{
window.location.href="pc端访问的链接";
}
</script>
简化一下
var p = navigator.platform;
if(p.indexOf("Win")<0){
alert("请在PC端使用");
}else{
window.location.href="pc端访问的链接";
}
网友评论