手机版和PC版识别

 

1.通过User-Agent

       //判断 是否来自手机终端
        public bool checkMoble()
        {
            if (isUserCheckMobile == false)
                return false;

            string userAgent = Request.Headers["User-Agent"];
            if (userAgent.IndexOf("Noki") > -1 || // Nokia phones and emulators     
                     userAgent.IndexOf("Android") > -1 ||   //Android 手机
                       userAgent.IndexOf("iPhone") > -1 ||  //iPhone  手机
                     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)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

2.考虑asp.net mvc 
里面有for mobile的模版

3.获取浏览器的属性

HttpBrowserCapabilities bc=Request.Browser;
            Response.Write("<script language=‘javascript‘>alert(‘" + bc.Browser + "‘);</script>");

 4.js判断

<script type="text/javascript">
        var bro = navigator.userAgent;
        //alert(bro);
        // alert(bro.indexOf("Windows Phone"));
        // iPad 浏览器navigator.userAgent(包含iPad)
        if (bro.indexOf("NetFront") > 0 || bro.indexOf("UCWEB") > 0
            || bro.indexOf("iPhone") > 0 || bro.indexOf("Windows CE") > 0
            || bro.indexOf("MIDP-2.0") > 0 || bro.indexOf("Android") > 0
            || bro.indexOf("Opera Mini") > 0 || bro.indexOf("SymbianOS") > 0
            || bro.indexOf("Windows Phone") > 0) {
            window.open("Wap1/Index.aspx", "_top");
        }
        //        else if (bro.indexOf("Windows NT") > 0) {
        //            window.open("NewWeb/default.html", "_top");
        //        } 
                else {
                    window.open("NewWeb/default.html", "_top");
                }
    </script>

 

 

(如有问题到博主网站 blog.uoolo.com 或 wuchao.cnblogs.com 留言)

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。