当前位置 : 主页 > 网络编程 > JavaScript >

pc端地址适配移动端地址

来源:互联网 收集:自由互联 发布时间:2021-06-28
在手机端访问pc端的url地址,自动转跳到对应的m端地址 //判断当前设备类型,如果是在移动设备上面进入pc论坛,自动跳转到M端论坛function mobile_device_detect(url){ var thisOS=navigator.platform;
在手机端访问pc端的url地址,自动转跳到对应的m端地址
//判断当前设备类型,如果是在移动设备上面进入pc论坛,自动跳转到M端论坛

function mobile_device_detect(url){
  var thisOS=navigator.platform;
  var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
  for(var i=0;i
 
   -1){
  //   head = "house.m.";
  // }else{
  //   head = "prehouse.m.";
  // }
  if(g3=='wh'){
    port="wuhan/"
  }
  if(!g5){
    if(origin.indexOf('house.')>0){
      return g1+head+g4+'/';
    }else{
      return g1+head+g4+'/'+port+g2
    }
  }else{
    if(g5=='comment.html'){
      last = g2+'/comment';
    }else if(g5=='toComment.html'){
      last = g2+'/comment/write';
    }else if(g5=='housetype.html'){
      last = g2+'/housetype';
    }else if(g5.indexOf('album/t')>-1){
      last = g2+'/'+g5.replace(/([A-z]+)\/t(\d)\/i(\d)/,'$1/$2');
    }else if(g5.indexOf('album/l')>-1){
      last = g2+'/'+g5.replace(/([A-z]+)\/l(\d)/,function(match,g1,g2,index,origin){
        var curg2;
        switch(g2){
          case "1":
            curg2 = 5;
            break;
          case "2":
            curg2 = 3;
            break;
          case "3":
            curg2 = 2;
            break;
          case "4":
            curg2 = 7;
            break;
          case "5":
            curg2 = 4;
            break;
          case "6":
            curg2 = 101;
            break;
          case "7":
            curg2 = 102;
            break;
        }
        return g1+"/"+curg2;
      })
    }else if(g5.indexOf('housetype/h')>-1){
      last = g2+'/'+g5.replace(/([A-z]+)\/h(g\d+)\/sa/,'$1/$2');
    }else if(g5.indexOf('housetype/p')>-1){
      last = g2+'/'+g5.replace(/(\w+)\/p\d+\/([\w\d-]+)\.html/g,'$1/$2.html');
    }else if(origin.indexOf('house.')>0){
      if(g5.indexOf("area") || g5.indexOf("subway")){
        last = "";
        port = "";
      }else{
        last = g5;
      }
    }else if(origin.indexOf('price')>0){
      last = g2+'/detail.html'
    }else{
      last = g2+'/'+g5;
    }
    return g1+head+g4+'/'+port+last;
  }
})
 console.log(str);
 console.log(newLink);
mobile_device_detect(newLink);
 
上一篇:常用的 js 库.txt
下一篇:H5计算器实现
网友评论