If a web application, how can you figure out the visitor is viewing from a mobile phone?
is it also possible figure out the make/model like blackberry versus iphone?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You could check their User-Agent string.
Method 2
Scott Hanselman did a podcast on a module device database that Microsoft made available on Codeplex. It’s a .browser file that you put in your ASP.NET (version 2.0+) website, which then helps the framework define the Request.Browser property more closely. You should be able to get a lot of the information that you need from there.
However, that project is no longer supported, and when you’re dealing with user agent detection, having an up-to-date resource is very important. You should probably use a similar project, such as 51degrees.mobi or WURFL.
Even without that, at the least you can check Request.Browser.IsMobileDevice.
Method 3
You can check the User-Agent string. In JavaScript, that’s really easy, it’s just a property of the navigator object.
var useragent = navigator.userAgent;
You can check if the device if iPhone or Blackberry in JS with something like
var isIphone = !!agent.match(/iPhone/i),
isBlackberry = !!agent.match(/blackberry/i);
if isIphone is true you are accessing the site from an Iphone, if isBlackBerry you are accessing the site from a Blackberry.
You can use “UserAgent Switcher” plugin for firefox to test that.
Method 4
Use httpRequest.Browser.IsMobileDevice in Session_Start
void Session_Start(object sender, EventArgs e)
{
// Redirect mobile users to the mobile home page
HttpRequest httpRequest = HttpContext.Current.Request;
if (httpRequest.Browser.IsMobileDevice)
{
string path = httpRequest.Url.PathAndQuery;
bool isOnMobilePage = path.StartsWith("/Mobile/",
StringComparison.OrdinalIgnoreCase);
if (!isOnMobilePage)
{
string redirectTo = "~/Mobile/";
HttpContext.Current.Response.Redirect(redirectTo);
}
}
}
Method 5
Please, check this out. Worked fine for me!
http://detectmobilebrowsers.com/
Method 6
You need to check for User Agent.
Like… http://www.developershome.com/wap/detection/detection.asp?page=userAgentHeader
Method 7
Here is some information from a similar question:
Auto detect mobile browser (via user-agent?)
It involves reading the user-agent header. The answers to that other question include links for scripts for this.
Here is another helpful discussion:
Standard way to detect mobile browsers in a web application based on the http request
Method 8
As preciously stated – user agent
BUT, do you really mean to ask “is it a mobile phone”? Or do you really mean something else?
Lines are blurring these days. I bought a nice little Android slate with 7″ screen from eBay for $99. Is that a mobile phone? Is a mini-netbook with 6″ screen? Is a Kidnle-like-device?
I’m just wondering why you want to know if it is a mobile ‘phone … screen size? processing power? something else?
You probably did mean mobile ‘phone but, if not, please rephrase and we can help further.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0