金玲

导航

 
  1. 转:http://free0007.iteye.com/blog/2017329
  2. /// 根据 Agent 判断是否是智能手机    
  3. ///</summary>    
  4. ///<returns></returns>    
  5. public static bool CheckAgent()    
  6. {    
  7.     bool flag = false;    
  8.   
  9.     string agent = HttpContext.Current.Request.UserAgent;    
  10.     string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };    
  11.   
  12.        //排除 Windows 桌面系统    
  13.         if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;")))    
  14.         {    
  15.             //排除 苹果桌面系统    
  16.             if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh"))    
  17.             {    
  18.                 foreach (string item in keywords)    
  19.                 {    
  20.                     if (agent.Contains(item))    
  21.                     {    
  22.                         flag = true;    
  23.                         break;    
  24.                     }    
  25.                 }    
  26.             }    
  27.         }    
  28.   
  29.     return flag;    
  30. }   

 

 

function getPlatform()
{//设置平台信息
var platform = -1;
var agent = navigator.userAgent.toLowerCase();
if((/android/gi).test(agent))
{
platform = 1;
}
else if((/iphone/gi).test(agent))
{
platform = 2;
}
else
{
platform = 1;
}
return platform;
}
posted on 2015-11-05 10:04  金_玲  阅读(2181)  评论(0编辑  收藏  举报