日期:2014-05-17  浏览次数:20719 次

如何判断是手机访问网站还是电脑访问网站
如何判断是手机访问网站还是电脑访问网站?
需要详细的代码。



------解决方案--------------------
Java code

String userAgent = "";  
        String userAgents=request.getHeader("user-agent");  
          
        if(userAgents != null ){  
        userAgent  = userAgents;  
        userAgent = userAgent.toUpperCase();  
        }  
    //out.print(">>>>"+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("OPER") > -1 || //Opera  
                userAgent.indexOf("DOPOD") > -1 ||  //多普达  
                userAgent.indexOf("SYMBIAN") > -1   //symbian系统  
                ) {  
       //通过手机访问  
    }  else {

       //PC
    }

------解决方案--------------------
一楼很全了,佩服

就是通过用户的User-Agent 这个http头判断
------解决方案--------------------

通过javascript判断User-Agent或者判断浏览器的版本。+1