Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Keith Bush 1 post 21 karma points
    Sep 06, 2013 @ 04:25
    Keith Bush
    0

    Help with mobile site detection

    Guys I will apologize first. I have an offline client and I have built a mobile site for his business. I however, did not build his main website which used umbraco, which I know absolutely nothing about. I have the log in for his website through umbraco but we can't get to his hosting files at all. His previous developer is MIA, he is however maintaining the hosting account. My question is this, is there anyway to install a redirect or mobile detection through umbraco without getting into the files, which is my preferred method. I know that through wordpress that you can install plugins that will detect or redirect to mobile sites. Hoping there is a solution to this problem.

    Thanks

  • lothar 25 posts 99 karma points
    Sep 11, 2013 @ 11:26
    lothar
    0

    You could do this with javascript.

    I'm using this script to detect if it is mobile device: http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/

    There are other javascript mobile detecters that detect more browsers but this one checks the most popular ones, just to clarify.

     

    You need to add the javascript into the main template so it'll be reachable by every page.

    You can find the templates by logging into umbraco and going to the 'Settings' section at the bottom.

    Then at the left column you have the templates, now you add the javascript below to the main template (mostly there is only 1 main template but there could be more, just saying):

    <script>
    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()); } };

    if (isMobile.any()) {
    // redirect to mobile site
    window.location = "yourMobileSiteUrl";
    }
    </script>

    This will then check on every page if it's a mobile device and when it is it'll redirect to the mobile site.

Please Sign in or register to post replies

Write your reply to:

Draft