• Java与JS判断请求来是否来自移动端


    Java

     1 public boolean JudgeIsMoblie(HttpServletRequest request) {  
     2                 boolean isMoblie = false;  
     3                 //String[] mobileAgents = { "iphone", "android", "phone", "mobile", "wap", "netfront", "java", "opera mobi","opera mini","ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod",  "nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos",  "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian","ericsson", "philips", "sagem","wellcom", "bunjalloo", "maui","smartphone", "iemobile", "spice", "bird", "zte-", "longcos","pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac","blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs","kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi","mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port","prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem","smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v","voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-","Googlebot-Mobile" };  
     4                 String [] mobileAgents = {"android" , "Android" , "iphone", "iPhone" , "SymbianOS" , "Windows Phone", "iPad" , "ipad" , "ipod" , "iPod"};
     5                 if (request.getHeader("User-Agent") != null) {  
     6                     System.out.println(request.getHeader("User-Agent"));
     7                     for (String mobileAgent : mobileAgents) {  
     8                         if (request.getHeader("User-Agent").toLowerCase().indexOf(mobileAgent) >= 0) {  
     9                             isMoblie = true;  
    10                             break;  
    11                         }  
    12                     }  
    13                 }  
    14                 return isMoblie;  
    15             }
     

      JS

    var IsPC = function(){
                var userAgentInfo = navigator.userAgent;
                var Agents = ["Android", "iPhone",
                            "SymbianOS", "Windows Phone",
                            "iPad", "iPod"];
                var flag = true;
                for (var v = 0; v < Agents.length; v++) {
                    if (userAgentInfo.indexOf(Agents[v]) > 0) {
                        flag = false;
                        break;
                    }
                }
                return flag;
            }
  • 相关阅读:
    Android+Eclipse+Java:在“正在启动 CrazySnake”期间发生了内部错误, java.lang.NullPointerException
    ActivityManager: Warning: Activity not started, its current task has been brought to the front 的的问题
    CLR via C#(15)--String,熟悉而又陌生
    CLR via C#(14)-可空值类型,关于?和??的故事
    CLR via C#(13)-浅谈事件
    CLR via C#(12)-委托Delegate
    CLR via C#(11)-无参属性、有参数属性(索引器)
    CLR via C#(10)-参数
    CLR via C#(09)-扩展方法
    CLR via C#(08)-操作符
  • 原文地址:https://www.cnblogs.com/remember-forget/p/8873627.html
Copyright © 2020-2023  润新知