Embed
Email

Mobile User-Agent Detection

Document Sample

Shared by: Kerala g
Categories
Tags
Stats
views:
0
posted:
12/7/2011
language:
pages:
3
Mobile user-agent detection



This document attempts to determine the most reliable way of detecting mobile user

agents. Since the test device is running Windows 2003 CE, only browsers compatible

with this platform are used.



The used browsers are:



 Pocket IE 6.0

 Opera 8.0u1



Detection through the HTTP_USER_AGENT header



The HTTP_USER_AGENT header of Pocket IE consists of the following:



Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Smartphone;

240x320; SPV C550; OpVer 8.2.3.8)



The HTTP_USER_AGENT header of Opera consists of the following:



Mozilla/4.0 (compatible; MSIE 6.0; Windows CE) Opera 8.0 [en]



The common value in these strings is ”Windows CE”, so this might be useable for

detection. However, to make the detection more reliable, we need to dig deeper,

since this header can easily be modified or faked.



Detection through the HTTP_ACCEPT header



The HTTP_ACCEPT header of Pocket IE consists of the following:



application/vnd.wap.wmlc, application/vnd.wap.wbxml,

application/vnd.wap.wmlscriptc,

application/vnd.wap.multipart.mixed,

application/vnd.wap.xhtml+xml, application/xhtml+xml,

application/vnd.oma.dd+xml, audio/3gpp, audio/mid, audio/midi,

audio/sp-midi, audio/amr, audio/amr-wb, audio/mp3, audio/mp4,

audio/MP4-LATM, audio/mpeg, audio/wav, audio/x-wav, audio/x-

mp3, audio/x-mpeg, audio/x-mpg, audio/x-ms-wax, audio/x-ms-

wma, audio/x-ms-wav, image/bitmap, image/bmp, image/gif,

image/jpeg, image/jpg, image/pjpeg, image/png,

image/vnd.wap.wbmp, image/wbmp, image/x-bmp, image/x-png,

image/x-windows-bmp, message/rfc822, text/css, text/html,

text/plain, text/vnd.wap.wml, text/x-ical, text/xml, text/xsl,

text/x-vcal, application/java, application/java-archive,

/vnd.sun.j2me.app-descriptor, video/3gpp, video/avi, video/x-

ms-avi, video/mp4, video/x-ms-asf, video/x-ms-asx, video/x-ms-

wm, video/x-ms-wmp, video/x-ms-wmv, video/x-ms-wmx, video/x-

ms-wvx, */*









1

The HTTP_ACCEPT header of Opera consists of the following:



text/html, application/xml;q=0.9, application/xhtml+xml,

image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1



From the HTTP_ACCEPT headers sent by IE, the following values are useful:



Header value Possible purpose

application/vnd.wap.wmlc Detection of WAP compatibility

application/vnd.wap.wmlscriptc

application/vnd.wap.multipart.mixed

application/vnd.wap.xhtml+xml

image/vnd.wap.wbmp

image/wbmp

text/vnd.wap.wml

image/gif Detection of HTML compatibility

image/jpg

image/jpeg

image/png

text/html



From the HTTP_ACCEPT headers sent by Opera, the following values are useful:



Header value Possible purpose

image/gif Detection of HTML compatibility

image/jpeg

image/png

text/html



As you can see IE allows for WAP detection through this header; roughly you could

say that WAP compliancy + HTML compliancy = Mobile device.



For Opera, this is different, as we can only detect that it can handle HTML pages

through the HTTP_ACCEPT header.



Note that most WAP-only browsers do send the WML* values, so this can be quite

reliable for detecting support for this technology. On the other hand, both IE and

Opera support WML, so in that sense, there’s no reason to write specific HTML

pages for mobile browsers.









2

Detection through CSS



The following CSS is correctly interpreted by both IE and Opera:



@media handheld {

BODY { color: red; font-size: xx-small }

}



This CSS can be applied to format the page layout for mobile devices as well as

hiding specific sections for mobile and regular web browsers.



Detection through JavaScript



The following JavaScript is handled correctly by both IE and Opera:



document.write('Screen width:', screen.width);



The width property of the screen object returns the width of the display. As a rule

you could say that anything below 640 pixels can be regarded as a mobile device

and can be redirected to a specific location.



Drawback of this detection method, of course, is that JavaScript runs on the client

and can be disabled. In this case, the noscript tag can be used in addition,

showing a message and some links to select from.



But this can get tedious when browsing from a PC (where users tend to customize

default browser settings more often).



Conclusion



So, what’s the most reliable way of detecting a mobile web browser? In short, there is

no full proof method to do this.



But there are some rules which might allow you to catch most exceptions:



1. HTTP_USER_AGENT contains Windows CE:

Mobile browser (IE/Opera);

2. HTTP_ACCEPT contains the substring vnd.wap:

WAP browser (IE/WAP Browsers);

3. HTTP_ACCEPT contains the substring text/html:

HTML browser (IE/Opera);

4. HTTP_ACCEPT contains both substrings vnd.wap and text/html:

Mobile browser (IE);

5. JavaScript screen.width property returns a value below 640:

Mobile browser (IE/Opera);

6. The CSS @media handheld property is parsed:

Mobile browser (IE/Opera).



From these rules, the most reliable ones appear to be rule #2 to detect WAP

compliant browsers and rule #6 to detect handheld devices in general.





3



Related docs
Other docs by Kerala g
union-budget-2012-13-highlights
Views: 81  |  Downloads: 0
notification M.Tech_05-03-09
Views: 56  |  Downloads: 0
India_Customs Regulation 1
Views: 52  |  Downloads: 0
CE Notification 39-2011-12.9.2011
Views: 50  |  Downloads: 0
STATISTICS
Views: 69  |  Downloads: 0
A Hero (R.K. Narayan)
Views: 87  |  Downloads: 6
RRBPatna-Info-HN
Views: 98  |  Downloads: 0
RRB-Notice-Para
Views: 100  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!