我的主页是index.html,我想让登陆进入网站的用户分析是电脑的登陆进入cindex.html。如果是手机(或移动设备)登陆进入的,那就进入mindex.html,求大神分析代码,万般感谢,我知道index.asp的代码:http://zhidao.baidu.com/question/568974406.html?qbl=relate_question_0
但我的是index.html的,html的无效
1、首先根据下方的代码,进行输入编辑。
<script type="text/javascript">
try{
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
window.location.href="mindex.html";
2、然后继续根据下方的代码,进行输入编辑。
}else{
window.location.href="cindex.html";
}
}catch(e){}
</script>
3、然后这样就可以判断手机还是电脑登陆进入了。
温馨提示:答案为网友推荐,仅供参考
第1个回答 2019-03-30
方法有很多,核心就是navigator对象获取访问设备的相关属性,再做判断;
比如:
function goPAGE() { if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { window.location.href="你的手机版地址";} else { window.location.href="你的电脑版地址"; }}还有比较简便的;
应该都是可以的,结合自身环境选用恰当的方式即可。
第2个回答 推荐于2017-11-26
这个是js的命令 写在head之间就可以的追问
try{
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
window.location.href="mindex.html";
}else{
window.location.href="cindex.html";
}
}catch(e){}
</script>
求代码
追答<script type="text/javascript">try{
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
window.location.href="mindex.html";
}else{
window.location.href="cindex.html";
}
}catch(e){}
</script>
测试下看是否可用
追问我的服务器最近繁忙无法登陆,能不能帮我试一下这个代码呢?谢谢,我等等加分
追答可以使用 没问题 但是要记住 只有主页加 cindex.html 和mindex.html 别加 要不会循环追问谢谢。可以,你真厉害。谢谢了,以后请教你,求加Q:9④1⑦5三5④5,拜您为师了
本回答被提问者采纳