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;
        }

原文地址:https://www.cnblogs.com/remember-forget/p/8873627.html

时间: 2024-10-12 13:02:22

Java与JS判断请求来是否来自移动端的相关文章

JS判断请求来自Android手机还是iPhone手机

<script type="text/javascript"> var browser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return { //移动终端浏览器版本信息 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android')

asp.net Core 使用过滤器判断请求客户端是否为移动端,并实现PC端和移动端请求映射和自动跳转

很多时候我们做网站时单纯的用bootstrap等前端框架实现的前端自适应带给用户的体验并不太好,所以为了提高用户体验会专门针对PC端网页重新设计一套移动端网页,但是怎么才能做到在移动端访问PC页面的时候返回对应的移动端页面,而不是PC端页面呢?下面我们就简单的进行介绍.主要技术是asp.net core. 第一步:自定义一个校验请求客户端类型的过滤器.该过滤器要实现3个功能:1.能够校验请求客户端为移动端还是PC端:2.能够配置请求路径的映射,即当前请求的PC端的路径对应的移动端路径:3.能够配

JS判断请求来自Android手机还是iPhone手机,根据不同的手机跳转到不同的链接。

<script type="text/javascript">var browser = {versions: function () {var u = navigator.userAgent, app = navigator.appVersion;return { //移动终端浏览器版本信息 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') >

java,js判断全角半角

function chkHalf(str){ for(var i=0;i { strCode=str.charCodeAt(i); if((strCode>65248)||(strCode==12288)){ alert("有全角字符"); break; } } } if(str.getBytes().length==string.length){ //全是半角 } if(str.getBytes().length > str.length && str.g

js判断用户使用设备及移动端竖屏代码实现

var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //苹果.谷歌内核 gecko: u.

js判断终端是PC还是移动端

function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); var flag = true; for (var v = 0; v < Agent

js判断浏览器内核和版本(包括手机端设备)

var X, xue;xue = xue || function(expr, fn) {    return xue.dom ? xue.dom(expr, fn) : {};};X = xue;window.xue = xue; xue.browser = xue.browser || {};xue.browser.uga = navigator.userAgent.toLowerCase(); xue.browser.mozilla = /firefox/.test(xue.browser.

JS判断设备类型跳转至PC端或移动端相应页面

if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { //window.location.href="你的手机版地址"; }else{ //window.location.href=

js判断设备是都是pc端

function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); var flag = true; for (var v = 0; v < Agent