Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect a mobile browser, and direct appropriate content to it?

I've read that its bad (not advised) to use User Agent Sniffing to send down the correct content for a mobile browser, so I'm wondering what IS the best way to do this?

I'm using ASP.NET MVC, and I've built my site and it works well on desktop browsers, so I'm looking to begin building a mobile version. When a mobile browser comes to my site, I'd like to use a different set of Views, which ideally posses the following attributes:

  1. Link to pre-scaled images
  2. Use minimal javascript
  3. Remove all but essential content

My first thought was to sniff the user agent, and then send down a different .CSS file, but as stated above I've read that this is a bad way to do this, so I'm asking you for your thoughts.

like image 784
Nate Avatar asked Aug 16 '10 20:08

Nate


People also ask

What is the best way to detect a mobile device?

In summary, we recommend looking for the string “Mobi” anywhere in the User Agent to detect a mobile device. Like this: if (/Mobi/. test(navigator.

How does a website identify a mobile device?

It works by examining information contained in the HTTP headers, particularly User Agent strings sent by all web-enabled devices. The User Agent is looked up in a database that returns any requested information including device type.

How do you detect whether the website is being opened in a mobile device or a desktop in Javascript?

We can use the CSS media queries to check whether the website is opened inside a web browser or a mobile browser. This information can be fetched using the min-width and the max-width of the webpage.

What is considered a mobile browser?

What is a mobile browser? A mobile browser is one that is optimized for the small display screen and limited resources of a handheld computing device such as a smart phone. A mobile browser interface is simplified to display content in the smallest viable space.


2 Answers

The user agent is really all you have in a HTTP GET request, but you should let someone else maintain the list. We use the Microsoft Mobile Device Browser File with a custom view engine in a manner roughly similar to this Scott Hanselman post.

like image 60
Craig Stuntz Avatar answered Nov 15 '22 07:11

Craig Stuntz


The best way to detect a mobile browser is to use this wonderful codeplex project:

http://mdbf.codeplex.com/

For background on how you could create targeted views read here:

http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx

like image 37
Keith Adler Avatar answered Nov 15 '22 08:11

Keith Adler