判断访问端是手机还是电脑

  1. <SCRIPT LANGUAGE="JavaScript">  
  2.   
  3.     //客户端判断  
  4.       mobile_device_detect();  
  5.   
  6.     function mobile_device_detect() {  
  7.   
  8.         var appurl = "http://www.baidu.com/";  /* 移动端访问地址 */  
  9.         var weburl = "http://www.douyutv.com/";  /* pc端访问地址 */  
  10.           
  11.         var thisOS = navigator.platform;  
  12.         var os = new Array("iPhone", "iPod", "iPad", "android", "Nokia",  
  13.                 "SymbianOS", "Symbian", "Windows Phone", "Phone",  
  14.                 "Linux armv71", "MAUI", "UNTRUSTED/1.0", "Windows CE",  
  15.                 "BlackBerry", "IEMobile");  
  16.         for (var i = 0; i < os.length; i++) {  
  17.             if (thisOS.match(os[i])) {  
  18.                 window.location = appurl;  
  19.             }else{  
  20.                 window.location = weburl;    
  21.             }  
  22.   
  23.         }  
  24.         //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认  
  25.         if (navigator.platform.indexOf('iPad') != -1) {  
  26.             window.location = appurl;  
  27.         }else{  
  28.             window.location = weburl;    
  29.         }  
  30.         //做这一部分是因为Android手机的内核也是Linux  
  31.         //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断  
  32.         var check = navigator.appVersion;  
  33.         if (check.match(/linux/i)) {  
  34.             //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件  
  35.             if (check.match(/mobile/i) || check.match(/X11/i)) {  
  36.                 window.location = appurl;  
  37.             }else{  
  38.                 window.location = weburl;   
  39.             }  
  40.         }  
  41.         //类in_array函数  
  42.         Array.prototype.in_array = function(e) {  
  43.             for (i = 0; i < this.length; i++) {  
  44.                 if (this[i] == e)  
  45.                     return true;  
  46.             }  
  47.             return false;  
  48.         }  
  49.     }  
  50.       
  51.        
  52. </SCRIPT>  

转载于:https://my.oschina.net/zyt1978/blog/689587

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值