Project / Support Center
Welcome, Guest. Please login or register. May 22, 2012, 10:28: PM
Home Help Search Login Register
D-Web Web Site Creator D - Web Web Site Creator On-line HTML Editor No Programming knowledge required. Web Global Net PayPal-Cart Shopping Cart System PayPal - Kart Shopping Cart System for E-Commerce over the internet, that's easy to use. Web Global Net Newsletter Manager Newsletter Manager On-line Newsletter Creator with Email Subscriber Management.
Ring Central Discount
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  Mobile Devices  |  Topic: Detecting mobile and tablets 0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: Detecting mobile and tablets  (Read 251 times)
Web Global Net
Administrator
******
Offline Offline

Posts: 1,685


« on: January 20, 2012, 10:08: AM »

http://our.umbraco.org/forum/templating/templates-and-document-types/18616-Detecting-mobile-and-tablets

Detecting mobile and tablets
Carlos started this topic 10 months ago , this topic was edited at: Saturday, April 30, 2011 8:05 AM
So I wrote a post a while back on how we detected mobile devices and tablets and redirected them to different templates defined by the author.  HERE IS THE LINK.

HOWEVER, my inclination about detecting Android tablets was wrong.  We were using in template C# in our Global template. We didn't want to use 51Degrees.mobi since it would not fit our needs. However, being in contact with the person over at 51Degrees.mobi, he is planning on working with the Umbraco people to help integrate 51degrees into Umbraco more gracefully.

Ok Android tablet detection.
We were using string.Contains("Android") this got everything that was containing the user agent "Android". This didn't work in differentiating between mobile and tablet. My mistake.  So my work around was this huge client site JS solution that kind of work part of the time.

Simple solution I did today. strUserAgent.Contains("Android") && !strUsrAgent.Contains("mobile"). Found out HERE that recommended by the Android dev team to no include "mobile" if you want your tablet to redirect to a mobile template. Or if you want to redirect to a tablet specific or desktop version of your site. 
The solution below should cover all Android tablets so you don't have to look for specific devices.

Here is our full solution. Remember, we put this in our Global template in the <head> section.

 <script runat="server"> 

        protected string outof = "";

        protected void Page_Load(object sender, EventArgs e)

        {

            string strUserAgent = Request.UserAgent.ToLower();

            if (strUserAgent != null)

            {

                if (

                  Request.Browser.IsMobileDevice == true

                   || strUserAgent.Contains("iphone")

                   || strUserAgent.Contains("ipod")

                  || strUserAgent.Contains("android")

                  || strUserAgent.Contains("iemobile")

                  //|| strUserAgent.Contains("version")

                  //|| strUserAgent.Contains("blackberry")

                  //|| strUserAgent.Contains("windows ce")

                  //|| strUserAgent.Contains("opera mini")

                  //|| strUserAgent.Contains("palm")

                  //|| strUserAgent.Contains("chrome")

                  || strUserAgent.Contains("ipad")

                    )

                {

      //To detect iPad and Android tablet.

                  if (strUserAgent.Contains("ipad") || (strUserAgent.Contains("android") && !strUserAgent.Contains("mobile")))

                    {

                        if (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("chooseTabletTemplate") != null)

                        {

                            Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri + "/" + umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("chooseTabletTemplate").Value, true);

                        }

                    }

                    else

                    {

                        if (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("chooseMobileTemplate") != null)

                        {

                            Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri + "/" + umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("chooseMobileTemplate").Value, true);

                        }

                    }

                }

            }

        }

</script>
Report to moderator   Logged
Pages: [1] Go Up Send this topic Print 
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  Mobile Devices  |  Topic: Detecting mobile and tablets « previous next »
Jump to:  


Login with username, password and session length
Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!