如题。本人试过的方法有:
1).通过分辨率来判断,但发现目前有些手机分辨率也很大,其他一些手持设备(比如iPad)的分辨率也比较大。所以分辨率很多时候很难真正分辨出是来自手机或是电脑。
2).通过http head头信息中的User-Agent来分析来自手机还是电脑,但发现准确率也无法保证是100%。
请大家给点建议,不甚感激!
1).通过分辨率来判断,但发现目前有些手机分辨率也很大,其他一些手持设备(比如iPad)的分辨率也比较大。所以分辨率很多时候很难真正分辨出是来自手机或是电脑。
2).通过http head头信息中的User-Agent来分析来自手机还是电脑,但发现准确率也无法保证是100%。
请大家给点建议,不甚感激!
解决方案 »
- oracle数据导入问题
- java.lang.IllegalStateException:异常
- jsp+xslt+xml 在JBOSS下包的问题。
- (SSH项目)关于用户登陆问题.
- 请问除了解析SoapMessage外还有什么方法能够获得ServiceEndpoint!~~~~~~~
- JMS的应用服务器和2端没什么关联,那放在INTERNET上,别人连上来怎么办?
- ArrayLit怎么用?
- 如何写spring+hibernate的测试代码
- java中怎么执行liunx命令?
- 在eclipse+jboss-ide1.4+jboss4.0.0下jboss4.0.0不能启动,出现下面的错误,是什么原因,希望大家看看也许以后你会碰到?
- struts2的s:doubleselect 二级菜单没有值
- hibernate不能自动生成数据库求解
"iPad","iPhone","Android","MIDP","Opera Mobi",
"Opera Mini","BlackBerry","HP iPAQ","IEMobile",
"MSIEMobile","Windows Phone","HTC","LG",
"MOT","Nokia","Symbian","Fennec",
"Maemo","Tear","Midori","armv",
"Windows CE","WindowsCE","Smartphone","240x320",
"176x220","320x320","160x160","webOS",
"Palm","Sagem","Samsung","SGH",
"SIE","SonyEricsson","MMP","UCWEB"};private boolean checkMobile() {
String userAgent = request.getHeader("user-agent");
for (String mobile: MOBILE_SPECIFIC_SUBSTRING){
if (userAgent.contains(mobile)
|| userAgent.contains(mobile.toUpperCase())
|| userAgent.contains(mobile.toLowerCase())){
return true;
}
}
return false;
} 但不能100%的判断准确。比如电脑用户可以在firefox浏览器设置User-Agent,可以模拟手机环境访问。
但我觉得以上代码我觉可以判断99%的手机用户了。
以下是绝大部分手机获取User-Agent的特点
1. “iPhone” – all iPhone models contain string “iPhone” in their user agent properties.
2. “Android” – same note as above with some exceptions.
3. “MIDP” – many mobile devices contain string “MIDP”. Some of this devices can have screen big enough to properly display regular version of your site. So think..
4. “Opera Mobi” – some of mobiles contain this string detecting mobile version of Opera.
5. “Opera Mini” – some of mobiles contain this string …
6. “BlackBerry” – one of most popular smartphones.
7. “HP iPAQ” – Hewlett Packard smartphone?
8. “IEMobile” – microsoft IE mobile version.
9. “MSIEMobile” – the same as above.
10.”Windows Phone” – microsoft mobile OS detection.
11.”HTC” – sometimes htc phones contain nothing specific but this.
12.”LG” – LG.
13.”MOT” – Motorola.
14.”Nokia” – just Nokia.
15.”Symbian” – Symbian OS detection.
16.”Fennec” – mobile Firefox.
17.”Maemo” – linux version from Nokia. Is it may be used only on phones?
18.”Tear” – some mobile browser from/for Nokia?
19.”Midori” – it seems like Nokia gays have nothing to do. For what so many browsers?
20.”armv6l” – some string detecting Nokia phones.
21.”armv7l” – .. above. “armv” can be used as generic version.
22.”Windows CE”.
23.”WindowsCE” – variant of above.
24.”Smartphone” – some smartphones (why not all?!) contain this string.
25.”240×320″ – .. above. I see the future: soon (already?) web designers will take these parameters directly to their site width and height.
26.”176×220″, “320×320″, “160×160″ – same as above.
27.”webOS” – Palm webOS detection.
28.”Palm” – just Palm.
29.”Sagem” – more less known phone.
30.”Samsung”.
31.”SGH” – Samsung.
32.”Siemens”, “SIE” – Siemens.
33.”SonyEricsson”.
34.”MMP” some phones contain this string in their user-agents.
35.”UCWEB” – just another mobile browser.
36. “iPad” – all iPad models contain string “iPad” in their user agent properties.
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
可以结合判断User-Agent和屏幕分辨率来判断。
如果你的系统是BS结构的话,还可以通过自定义协议方式来做的。 看看有没有高人出来说两句。
我是否来着手机wap
能完全区分吗