码迷,mamicode.com
首页 > 移动开发 > 详细

浏览器判断终端是手机还是电脑

时间:2015-03-06 20:28:27      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

  protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Request.Headers["User-Agent"].ToString() + "<br/>");
        //Response.Write()
        string agent = Request.Headers["User-Agent"];
        if (choose_net(agent))
        {
            Response.Write("手机");
        }
        else
        {
            Response.Write("电脑");
        }
    }
    //对用户访问进行判断 如果是手机的话返回true,否则返回false
    public bool choose_net(String userAgent)
    {
        if (userAgent.IndexOf("Noki") > -1 || // Nokia phones and emulators     
                 userAgent.IndexOf("Eric") > -1 || // Ericsson WAP phones and emulators     
                 userAgent.IndexOf("WapI") > -1 || // Ericsson WapIDE 2.0     
                 userAgent.IndexOf("MC21") > -1 || // Ericsson MC218     
                 userAgent.IndexOf("AUR") > -1 || // Ericsson R320     
                 userAgent.IndexOf("R380") > -1 || // Ericsson R380     
                 userAgent.IndexOf("UP.B") > -1 || // UP.Browser     
                 userAgent.IndexOf("WinW") > -1 || // WinWAP browser     
                 userAgent.IndexOf("UPG1") > -1 || // UP.SDK 4.0     
                 userAgent.IndexOf("upsi") > -1 || //another kind of UP.Browser     
                 userAgent.IndexOf("QWAP") > -1 || // unknown QWAPPER browser     
                 userAgent.IndexOf("Jigs") > -1 || // unknown JigSaw browser     
                 userAgent.IndexOf("Java") > -1 || // unknown Java based browser     
                 userAgent.IndexOf("Alca") > -1 || // unknown Alcatel-BE3 browser (UP based)     
                 userAgent.IndexOf("MITS") > -1 || // unknown Mitsubishi browser     
                 userAgent.IndexOf("MOT-") > -1 || // unknown browser (UP based)     
                 userAgent.IndexOf("My S") > -1 ||//  unknown Ericsson devkit browser      
                 userAgent.IndexOf("WAPJ") > -1 ||//Virtual WAPJAG www.wapjag.de     
                 userAgent.IndexOf("fetc") > -1 ||//fetchpage.cgi Perl script from www.wapcab.de     
                 userAgent.IndexOf("ALAV") > -1 || //yet another unknown UP based browser     
                 userAgent.IndexOf("Wapa") > -1 || //another unknown browser (Web based "Wapalyzer")    
                 userAgent.IndexOf("UCWEB") > -1 || //another unknown browser (Web based "Wapalyzer")    
                 userAgent.IndexOf("BlackBerry") > -1 || //another unknown browser (Web based "Wapalyzer")                     
                 userAgent.IndexOf("J2ME") > -1 || //another unknown browser (Web based "Wapalyzer")              
                 userAgent.IndexOf("Oper") > -1 ||
                 userAgent.IndexOf("Android") > -1 ||
            userAgent.IndexOf("mozilla") > -1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

 

浏览器判断终端是手机还是电脑

标签:

原文地址:http://www.cnblogs.com/engine/p/4319004.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!