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\");
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/
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).
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());
}
};
You could also look at the size of the screen (smaller size would possibly mean a mobile device), which should be accessible through javascript.