Java与JS判断请求来是否来自移动端
Java
public boolean JudgeIsMoblie(HttpServletRequest request) {
boolean isMoblie = false;
//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" };
String [] mobileAgents = {"android" , "Android" , "iphone", "iPhone" , "SymbianOS" , "Windows Phone", "iPad" , "ipad" , "ipod" , "iPod"};
if (request.getHeader("User-Agent") != null) {
System.out.println(request.getHeader("User-Agent"));
for (String mobileAgent : mobileAgents) {
if (request.getHeader("User-Agent").toLowerCase().indexOf(mobileAgent) >= 0) {
isMoblie = true;
break;
}
}
}
return isMoblie;
}
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;
}
Java与JS判断请求来是否来自移动端的更多相关文章
- js判断用户是客户端还是移动端
js判断用户是客户端还是移动端 Javascript 判断客户端是否为 PC 还是手持设备,有时候项目中需要用到,很方便的源生检测,方法一共有两种 1.第一种: function IsPC() { ...
- JS判断当前使用设备是pc端还是web端(转MirageFireFox)
js判断当前设备 最近用bootstrap做自适应,发现仍然很难很好的兼容web端和PC端的现实. 仔细观察百度,淘宝,京东等大型网站,发现这些网站都有对应不同客户端的子站. 站点 PC端url we ...
- asp.net Core 使用过滤器判断请求客户端是否为移动端,并实现PC端和移动端请求映射和自动跳转
很多时候我们做网站时单纯的用bootstrap等前端框架实现的前端自适应带给用户的体验并不太好,所以为了提高用户体验会专门针对PC端网页重新设计一套移动端网页,但是怎么才能做到在移动端访问PC页面的时 ...
- js 判断当前操作系统 ios, android, 电脑端
一 . js判断移动端的操作系统(ios或Android) $(function () { var u = navigator.userAgent; var isAndroid = u.index ...
- 【方法】JS判断当前页面环境:PC端/移动端,安卓/IOS,微信环境/QQ环境等等
[主要知识] 浏览器设备信息:navigator.userAgent(本文中主要用到知识) 浏览器版本信息:navigator.appVersion var ua = navigator.userAg ...
- JS判断请求来自Android手机还是iPhone手机,根据不同的手机跳转到不同的链接。
<script type="text/javascript">var browser = {versions: function () {var u = navigat ...
- JS判断请求来自Android手机还是iPhone手机
<script type="text/javascript"> var browser = { versions: function () { var u = navi ...
- java,js判断全角半角
function chkHalf(str){ for(var i=0;i { strCode=str.charCodeAt(i); if((strCode>65248)||(strCode==1 ...
- js判断客户端是pc还是移动端
navigator.userAgentNavigator 对象包含有关浏览器的信息.没有应用于 navigator 对象的公开标准,不过所有浏览器都支持该对象.userAgent 属性是一个只读的字符 ...
随机推荐
- java登录央行征信网站
package com.entrym.crawler.test; import java.util.HashMap; import java.util.Map; import org.apache.c ...
- MTK 精简ROM
PhaseBeam.apk--------------------------------------动态壁纸光之韵律(可删) Phone.apk--------------------------- ...
- android:versionCode和android:versionName 用途(转)
转自:http://blog.csdn.net/wh_19910525/article/details/8660416 Android的版本可以在androidmainfest.xml中定义,主要有a ...
- 关于UIGestureRecognizerState
UIGestureRecognizerState的定义如下 typedef enum { UIGestureRecognizerStatePossible, UIGestureRecognizerSt ...
- Eclipse Maven 配置setting.xml 的镜像远程仓库
1.在.m2中新建settings.xml文件 1.window-->Preferences-->Maven-->User Settings 3.点击open file 编辑将远程仓 ...
- swoole的进程模型架构
swoole的强大之处就在与其进程模型的设计,既解决了异步问题,又解决了并行. 主线程MainReactor swoole启动后主线程会负责监听server socket,如果有新的连接accept, ...
- 重新生成RF的测试库API文档
在dos窗口下执行如下命令: 命令:python -m robot.libdoc 库名称 生成的API文件名.html 例如:python -m robot.libdoc MongoDBLibrar ...
- Django SimpleCMDB API
编写一个API,当我们访问 http://192.168.216.128:8000/hostinfo/getjson 时,返回 json 格式的主机组和组成员信息: [root@localhost S ...
- /etc/issue
/etc/issue 与 /etc/motd 作用一致,都是用于显示欢迎信息,区别在于 /etc/issue 是在 login 提示符之前显示,而 /etc/motd 则在在用户成功登录系统之后显示 ...
- 【译】调优Apache Kafka集群
今天带来一篇译文“调优Apache Kafka集群”,里面有一些观点并无太多新颖之处,但总结得还算详细.该文从四个不同的目标出发给出了各自不同的参数配置,值得大家一读~ 原文地址请参考:https:/ ...