Reputation: 21329
How to check if a web page has been opened by a mobile browser or a computer browser. I tried this :
name = request.getHeader("User-Agent");
But it gives these type of results :
I cannot from the above two results,differentiate whether the web page was visited by a mobile phone or a computer. How do I do that ?
It will be great if I am able do this in Java.
Upvotes: 2
Views: 6510
Reputation: 10225
You could also look at the size of the screen (smaller size would possibly mean a mobile device), which should be accessible through javascript.
Upvotes: 0
Reputation: 11
this is a good link I just found:
http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
Upvotes: 1
Reputation: 349
Like Mikko wrote, no simple ways to detect mobile.
But you can try: http://code.google.com/p/php-mobile-detect/
And something like previous answer: http://detectmobilebrowsers.com/
Upvotes: 3
Reputation: 42114
There is not any simple 'mobile=true' flag. You simply have to check by yourself. From here you can find subset of of values to search (list is rather old, so newer mobile browsers should be added).
Upvotes: 2