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

  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>  
相关文章
相关标签/搜索