public static bool CheckAgent() 
{ 
  bool flag = false; 
  string agent = HttpContext.Current.Request.UserAgent; 
  string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" }; 
  //排除 Windows 桌面系统 
  if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;"))) 
  { 
    //排除 苹果桌面系统 
    if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh")) 
    { 
      foreach (string item in keywords) 
      { 
        if (agent.Contains(item)) 
        { 
          flag = true; 
          break; 
        } 
      } 
    } 
    flag = true;
  } 
  return flag; 
  }

代码解释:
1. !agent.Contains("Windows NT") && !agent.Contains("Macintosh") 排除Window 桌面系统 和 苹果桌面系统
2. "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" 这些是判断智能设备Agent中的关键词
3. MQQBrowser 为 QQ 手机浏览器,QQ 手机的Agent 比较特殊,所以单独判断(在目前的Android系统中,只有该浏览器支持Html5语言)。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2021-11-14
  • 2021-10-11
  • 2021-06-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-09-16
  • 2021-12-14
相关资源
相似解决方案