当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS前端开发判断是否是手机端并跳转操作(小结)

JS前端开发判断是否是手机端并跳转操作(小结)

2019年03月27日  | 移动技术网IT编程  | 我要评论

常用跳转代码

<script type="text/javascript">
 // borwserredirect
 (function browserredirect(){
  var suseragent = navigator.useragent.tolowercase();
  var bisipad = suseragent.match(/ipad/i) == 'ipad';
  var bisiphone = suseragent.match(/iphone os/i) == 'iphone os';
  var bismidp = suseragent.match(/midp/i) == 'midp';
  var bisuc7 = suseragent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
  var bisuc = suseragent.match(/ucweb/i) == 'web';
  var bisce = suseragent.match(/windows ce/i) == 'windows ce';
  var biswm = suseragent.match(/windows mobile/i) == 'windows mobile';
  var bisandroid = suseragent.match(/android/i) == 'android';
  if(bisipad || bisiphone || bismidp || bisuc7 || bisuc || bisce || biswm || bisandroid ){
  window.location.href = '跳转的移动端网址';
  }
 })();
 </script>
<script type="text/javascript"> 
<!-- 
  //平台、设备和操作系统 
  var system = { 
   win: false, 
   mac: false, 
   xll: false, 
   ipad: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); 
  system.ipad = (navigator.useragent.match(/ipad/i) != null)?true:false; 
  //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面 
  if (system.win || system.mac || system.xll||system.ipad) { 
  } else { 
   window.location.href = "http://www.jdpatro.com/3g/"; 
  } 
--> 
</script>

腾讯跳转

<script type="text/javascript">
if(window.location.tostring().indexof('pref=padindex') != -1){
}else{
 if(/applewebkit.*mobile/i.test(navigator.useragent) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.useragent))){ 
  if(window.location.href.indexof("?mobile")<0){
  try{
   if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.useragent)){
    window.location.href="http://xw.qq.com/index.htm";
   }else if(/ipad/i.test(navigator.useragent)){
    //window.location.href="http://www.qq.com/pad/"
   }else{
    window.location.href="http://xw.qq.com/simple/s/index/"
   }
  }catch(e){}
 }
 }
}
</script>
<script type="text/javascript"> 
<!-- 
  //平台、设备和操作系统 
  var system = { 
   win: false, 
   mac: false, 
   xll: false, 
   ipad: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); 
  system.ipad = (navigator.useragent.match(/ipad/i) != null)?true:false; 
  //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面 
  if (system.win || system.mac || system.xll||system.ipad) { 
  } else { 
   window.location.href = "http://www.jdpatro.com/3g/"; 
  } 
--> 
</script>

js 判断浏览器客户端类型(ipad,iphone,android)

<script type="text/javascript"> 
 var bforcepc = fgetquery("dv") == "pc"; 
 function fbrowserredirect(){ 
  var suseragent = navigator.useragent.tolowercase(); 
  var bisipad = suseragent.match(/ipad/i) == "ipad"; 
  var bisiphoneos = suseragent.match(/iphone os/i) == "iphone os"; 
  var bismidp = suseragent.match(/midp/i) == "midp"; 
  var bisuc7 = suseragent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; 
  var bisuc = suseragent.match(/ucweb/i) == "ucweb"; 
  var bisandroid = suseragent.match(/android/i) == "android"; 
  var bisce = suseragent.match(/windows ce/i) == "windows ce"; 
  var biswm = suseragent.match(/windows mobile/i) == "windows mobile"; 
  if(bisipad){ 
   var surl = location.href;  
   if(!bforcepc){ 
    window.location.href = "http://ipad.mail.163.com/"; 
   } 
  } 
  if(bisiphoneos || bisandroid){ 
   var surl = location.href;  
   if(!bforcepc){ 
    window.location.href = "http://smart.mail.163.com/"; 
   } 
  } 
  if(bismidp||bisuc7||bisuc||bisce||biswm){ 
   var surl = location.href;  
   if(!bforcepc){ 
    window.location.href = "http://m.mail.163.com/"; 
   } 
  } 
 } 
 function fgetquery(name){//获取参数值 
  var surl = window.location.search.substr(1); 
  var r = surl.match(new regexp("(^|&)" + name + "=([^&]*)(&|$)")); 
  return (r == null ? null : (r[2])); 
 } 
 function fshowverblock(){  
  if(bforcepc){ 
   document.getelementbyidx_x("dv_block").style.display = "block"; 
  } 
  else{ 
   document.getelementbyidx_x("ad_block").style.display = "block"; 
  } 
 } 
 fbrowserredirect(); 
 </script> 

以上所述是小编给大家介绍的js前端开发判断是否是手机端并跳转操作,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网