zoukankan      html  css  js  c++  java
  • 通过UserAgent判断智能手机(设备,Android,IOS)

    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;
    }
  • 相关阅读:
    基本排序算法汇总
    贪心算法题目汇总
    STL中sort
    栈和队列题目汇总
    cron 计划任务 在线配置
    各种less概念通俗解释
    node 子线程 进程
    内存池
    RPC简介
    koa express 对比
  • 原文地址:https://www.cnblogs.com/jinling/p/4938551.html
Copyright © 2011-2022 走看看