- 转:http://free0007.iteye.com/blog/2017329
- /// 根据 Agent 判断是否是智能手机
- ///</summary>
- ///<returns></returns>
- 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;
- }
- }
- }
- }
- return flag;
- }
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;
}