发布时间:2015-11-09 浏览:440次
当前路径:默默网络 > CMS相关 > 正文
js判断网站手机端和电脑端自动跳转

手机访问网站,自动跳转到手机页面:


<script type="text/javascript">
function IsPhone() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = false;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = true;
break;
}
}
return flag;
}
if (IsPhone()) {
window.location ="手机站网址";
};
</script>


电脑访问手机网站,自动跳转到该站PC页面。


<script type="text/javascript">
function IsPhone() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = false;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = true;
break;
}
}
return flag;
}
if (!IsPhone()) {
window.location ="电脑站网址";
};
</script>


电脑版手机版在一起时候


<script type="text/javascript">
  function IsPhone() {
      var userAgentInfo = navigator.userAgent;
      var Agents = ["Android", "iPhone",
                  "SymbianOS", "Windows Phone",
                  "iPad", "iPod"];
      var flag = false;
      for (var v = 0; v < Agents.length; v++) {
          if (userAgentInfo.indexOf(Agents[v]) > 0) {
              flag = true;
              break;
          }
      }
      return flag;
  }
  window.location =IsPhone()?"手机站网址":"电脑站网址";
</script>