Welcome to TalkGraphics.com
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Jan 2014
    Location
    Savannah, Georgia Area
    Posts
    305

    Question Redirect with User Agent

    Hi there!

    I hope one of you brilliant minds can help me out?
    I prefer for my site to take up the whole screen with minimal scrolling.
    Since Xara designed websites are not dynamic I was thinking of making 4 different sites.
    One each for Desktop, Phone, iPad and Android Tablet.
    With the script below in the header I can get redirects to the iPad and a phone.
    But am stumped as to what to do to seperate Android phones from tablets.
    I know it's something about Android Mobile is phone and Android No Mobile is tablet.
    But how do I get it in the script?
    Please... anybody?

    Thanks!

    <script>
    function detect() {
    var uagent = navigator.userAgent.toLowerCase();
    var mobile = false;
    var search_strings = [
    "iphone",
    "ipod",
    "series60",
    "symbian",
    "android",
    "windows ce",
    "windows7phone",
    "w7p",
    "blackberry",
    "palm"
    ];
    for (i in search_strings) {
    if (uagent.search(search_strings[i]) > -1) mobile = true;
    }
    return mobile;
    }
    if (detect()) window.location = "http://yourwebsite.com/Portable/";
    </script>

    <script>
    function detect() {
    var uagent = navigator.userAgent.toLowerCase();
    var mobile = false;
    var search_strings = [
    "ipad"
    ];
    for (j in search_strings) {
    if (uagent.search(search_strings[j]) > -1) mobile = true;
    }
    return mobile;
    }
    if (detect()) window.location = "http://yourwebsite.com/iPad/";
    </script>

  2. #2
    Join Date
    Aug 2000
    Location
    Placitas, New Mexico, USA
    Posts
    37,555

    Default Re: Redirect with User Agent

    You post was moderated which means only the moderators can see it first.

    It is approved now and I think you should have a few suggestions before too long.
    Gary W. Priester
    Mr. Moderator Emeritus Dude
    , Sir

    gwpriester.com | Custom-Stereograms.com | eyeTricks on Facebook






  3. #3
    Join Date
    Jan 2014
    Location
    Savannah, Georgia Area
    Posts
    305

    Default Re: Redirect with User Agent

    Thanks gwpriester... I hope so!

    Not sure why but I ended up using "Portable" when I meant Phone/Mobile in my original post.
    But this should not really matter for what I am hoping to accomplish!
    Last edited by dutchim; 02 February 2014 at 02:32 PM.

  4. #4
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    10,431

    Default Re: Redirect with User Agent

    You can possibly work from the lists here: http://www.useragentstring.com/pages...gentstring.php
    Acorn

  5. #5
    Join Date
    Jan 2014
    Location
    Savannah, Georgia Area
    Posts
    305

    Default Re: Redirect with User Agent

    Thanks Acorn... But now I'm even more confused than before!

    Looking at that list I have no idea what to make of it or how to implement it.

    Perhaps I really am dumber than I look?

  6. #6
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    10,431

    Default Re: Redirect with User Agent

    From what I read of your code, your are inviting the user's browser to identify itself.
    The for xx in search_strings is a way of finding a fragment of a phrase that describe the browser.
    I was suggesting you set up an array for a third set of search strings using the Mobile Browsers list at the given URL, where you have a loop for (k in search_strings) { ...} coupled with if (detect()) window.location = "http://yourwebsite.com/tablet/";.

    You could also point any tablet you have to
    http://whatsmyuseragent.com/ and examine the userAgent string that returns.
    Perhaps we should all contribute our device's userAgents here?
    As I'm on a computer, using Chrome, I'm showing
    Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36
    Acorn

  7. #7
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    10,431

    Default Re: Redirect with User Agent

    An alternative may be to ask the device what its pixel width and height are, but I have never played with mobiles to check what's the best way.
    Look at http://www.javascriptkit.com/howto/newtech3.shtml form a tablet or phone to see if window.screen is a general method.

    Acorn

  8. #8
    Join Date
    Jan 2014
    Location
    Savannah, Georgia Area
    Posts
    305

    Default Re: Redirect with User Agent

    Alright... Thank you for your input.
    I will see if I can figure it out with this new info.
    Never got into all the code going on behind the scenes...
    And can be quite overwhelming as I found out!

  9. #9
    Join Date
    Jan 2014
    Location
    Savannah, Georgia Area
    Posts
    305

    Default Re: Redirect with User Agent

    I think I figured it out. Went with the following solution:

    Replaced "android" with "mobile" in the variable i. Both browsers I tried on Android phone had "mobile" in their user agent... so still works.
    Then looked for just "android" in a new variable k. If present it gets forwarded to the tablet version... works!

    Thanks for pointing me to the websites. Sure helped!

    Richard

  10. #10
    Join Date
    Aug 2000
    Location
    Placitas, New Mexico, USA
    Posts
    37,555

    Default Re: Redirect with User Agent

    See, I told you someone would have some suggestions.
    Gary W. Priester
    Mr. Moderator Emeritus Dude
    , Sir

    gwpriester.com | Custom-Stereograms.com | eyeTricks on Facebook






 

 

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •