mobile site redirection

by zotown
9 replies
  • WEB DESIGN
  • |
Ok so I have a website and a mobile version of my website. Does anybody know of a script which automatically redirects to the mobile site when someone visits my site from a mobile device?

Thanks
#mobile #redirection #site
  • {{ DiscussionBoard.errors[7095069].message }}
  • Profile picture of the author zotown
    which version will you recommend? I would prefer php, however I have heard that the js script is better here.

    This isnt for wordpress btw.

    Thanks.
    Signature
    {{ DiscussionBoard.errors[7102641].message }}
    • Profile picture of the author Jay Moreno
      Originally Posted by zotown View Post

      which version will you recommend? I would prefer php, however I have heard that the js script is better here.

      This isnt for wordpress btw.

      Thanks.
      @zotown - there are three ways you can implement javascript redirect:

      1) based on screensize width
      2) based on useragent
      3) a combination of both

      Type 1 is the most basic form redirecting if the screen size is lower than a certain width that you pre-determine in your script. Whilst this is a very simple approach there are several issues i have come across:

      a) new android devices do not always report correctly the screen width often reporting wider than expected and more inline with a desktop browser - so the redirect doesn't kick in.
      b) i haven't tested this yet but am thinking the iphone5 it could possible also report a much wider screen size similar to that of a desktop visitor
      c) content is still loaded before the page redirects - making it much slower than a php based redirect

      Type 2 would be my preference over type1 if its coded correctly - the only concerns i have are as follows:

      a) certain older devices do not support javascript very well, namely older blackberries so could potentially freeze the mobile browser or simply get ignored.
      b) am also not 100% sure that google will follow the redirect.
      c) as with type1 they are both slower to detect and redirect than a php based script

      Type 3 would be my first choice for placing a redirect on a standard html site or you cant use a php detect and redirect - if you detect screen width and back it up with some form of user agent detection namely for the android you should be pretty well covered.

      I haven't tried this against the iPhone5 yet so it may need a little tweaking:

      HTML Code:
      <script type="text/javascript"> if (screen.width < 1024 || navigator.userAgent.toLowerCase().indexOf('android')!=-1) (window.location.replace("http://www.yourdomainhere.com")); </script>
      Personally I prefer PHP based useragent detection - depending how it is coded I find it a lot more reliable. People say that you have to update your script whenever a new phone comes out... that is simply not true. I guess it depends how the detection script has been developed.

      You should also consider deploying a cookie or alternative means to prevent returning visitors getting redirected back to the mobile site if they wish to view the desktop version. Most javascript based redirect scripts do not do that.

      Hopefully this helps you.

      Cheers,

      Jay
      Signature
      Sorry, I am too busy helping people to think of a cool signature!
      {{ DiscussionBoard.errors[7106125].message }}
      • Profile picture of the author zotown
        Originally Posted by Jay Moreno View Post

        @zotown - there are three ways you can implement javascript redirect:

        1) based on screensize width
        2) based on useragent
        3) a combination of both

        Type 1 is the most basic form redirecting if the screen size is lower than a certain width that you pre-determine in your script. Whilst this is a very simple approach there are several issues i have come across:

        a) new android devices do not always report correctly the screen width often reporting wider than expected and more inline with a desktop browser - so the redirect doesn't kick in.
        b) i haven't tested this yet but am thinking the iphone5 it could possible also report a much wider screen size similar to that of a desktop visitor
        c) content is still loaded before the page redirects - making it much slower than a php based redirect

        Type 2 would be my preference over type1 if its coded correctly - the only concerns i have are as follows:

        a) certain older devices do not support javascript very well, namely older blackberries so could potentially freeze the mobile browser or simply get ignored.
        b) am also not 100% sure that google will follow the redirect.
        c) as with type1 they are both slower to detect and redirect than a php based script

        Type 3 would be my first choice for placing a redirect on a standard html site or you cant use a php detect and redirect - if you detect screen width and back it up with some form of user agent detection namely for the android you should be pretty well covered.

        I haven't tried this against the iPhone5 yet so it may need a little tweaking:

        HTML Code:
        <script type="text/javascript"> if (screen.width < 1024 || navigator.userAgent.toLowerCase().indexOf('android')!=-1) (window.location.replace("http://www.yourdomainhere.com")); </script>
        Personally I prefer PHP based useragent detection - depending how it is coded I find it a lot more reliable. People say that you have to update your script whenever a new phone comes out... that is simply not true. I guess it depends how the detection script has been developed.

        You should also consider deploying a cookie or alternative means to prevent returning visitors getting redirected back to the mobile site if they wish to view the desktop version. Most javascript based redirect scripts do not do that.

        Hopefully this helps you.

        Cheers,

        Jay
        Thank you for that it was very helpful. Have you got a php script that you would recommend? Also would the php script redirect to any mobile device?

        Thanks.
        Signature
        {{ DiscussionBoard.errors[7108656].message }}
  • Profile picture of the author Jay Moreno
    Signature
    Sorry, I am too busy helping people to think of a cool signature!
    {{ DiscussionBoard.errors[7109111].message }}
  • Profile picture of the author Minista
    I always use that script on all my customers Websites to redirect to the mobile version.

    I use the javascript version...it's simple to integrate and it is working very well. I never get any complain.

    Find a redirection script here in many formats: The MobileESP Project: Easily detect mobile web site visitors » Download MobileESP
    Signature

    Google Maps Contact Extractor, a google maps scraper software (Scrape google places data)
    Yellow Pages Scraper software an easy to use Yellow pages scraper software
    Yelp Data Scraper software, extract data from yelp website.
    Management-Ware Extract Anywhere, Website data extractor software, create your scraper to extract data from almost any website. Door to door CRM software.

    {{ DiscussionBoard.errors[7123863].message }}

Trending Topics