pc与移动端互相跳转

2017-2-10来源:心得技巧人气:635

1、移动端检测是否是PC端浏览器
<script data-fixed="true">
  !function(){
    if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == false){
      location.href = 'PC地址';
    }
  }();
</script>
<!--ignore-->

2、PC端检测是否是移动设备

<script data-fixed="true">
  !function(){
    function params(u, p){
      var m = new RegExp("(?:&|/?)"+p+"=([^&$]+)").exec(u);
      return m ? m[1] : '';
    }
    if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == true && params(location.search, "from") != "mobile"){
      location.href = '移动端地址';
    }
  }();
</script>
<!--ignore-->