判断是否是手机浏览的方法

public static bool IsMobile()
    {
        string agent = (HttpContext.Current.Request.UserAgent + "").ToLower().Trim();
        if (agent == "" || agent.IndexOf("mozilla") != -1 || agent.IndexOf("opera") != -1) return false;
        return true;
    }

 

public bool IsWap()
    {
        string agent = (Request.UserAgent + "").ToLower().Trim();

        if (agent == "" || 
            agent.IndexOf("mobile") != -1 ||
            agent.IndexOf("mobi") != -1 ||
            agent.IndexOf("nokia") != -1 ||
            agent.IndexOf("samsung") != -1 ||
            agent.IndexOf("sonyericsson") != -1 ||
            agent.IndexOf("mot") != -1 ||
            agent.IndexOf("blackberry") != -1 ||
            agent.IndexOf("lg") != -1 ||
            agent.IndexOf("htc") != -1 ||
            agent.IndexOf("j2me") != -1 ||
            agent.IndexOf("ucweb") != -1 ||
            agent.IndexOf("opera mini") != -1 ||
            agent.IndexOf("mobi") != -1)
        {
            //终端可能是手机

            return true;
                        
        }

        return false ;
    }

 

posted @ 2013-04-12 13:13  老皆知  阅读(309)  评论(0编辑  收藏  举报