Results 1 to 6 of 6
  1. #1
    baldidiot is offline Private Member
    Join Date
    January 2010
    Posts
    4,253
    Thanks
    403
    Thanked 1,948 Times in 1,280 Posts

    Default Tab selection using javascript based on country

    This follows on from the geotargetting discussions we're having, but I didn't want to veer of on a tangent so putting this in it's own thread.

    On our new site we're looking at using jquery tabs for tables of casinos for different countries - one tab each for for UK, Europe, US, Canada and Australia. What I want to do is select the relevant tab based on the users country, but my knowledge of jquery/javascript is below limited.

    My main reason for this is so we can cache the whole page (well, almost all of it), and then use javascript to do the "geotargetting" after the page has loaded by selecting the relevant se(rather than having a more dynamic output of content). I see plenty of sites do this, so assuming it's possible, but not sure where to start.

    I know we need to store the country value and output it in a small section of code that's outside of the cache to make it available to the browser. I just don't know what to do with it after that...

    Any ideas?
    onlinegamblingwebsites.com - Formally known as goodbonusguide.
    baldidiot.net - Baldys affiliate blog. Will get updated one day. Maybe.

  2. #2
    slotplayer is offline Private Member
    Join Date
    September 2006
    Posts
    1,038
    Thanks
    194
    Thanked 323 Times in 252 Posts

    Default

    This is simple script I played with sometime ago to redirect players to a sorry page.

    The js script from: hxxp://www.geoplugin.com/ will return the country code.
    I modified my little redirect script to work with a hash tag but didn't test it so it might have some syntax errors.
    This will (should) open the correct tab based on country location when the site first loads.
    (You add the code from geo plugin to the head and the script below as well).

    I might add I'm not sure how Google will like it either.

    <script language="Javascript" type="text/javascript">
    <!--
    var loc = geoplugin_countryCode();

    if (loc =="UK") {

    window.location = "hxxp://mysite.com/index.htm#uk-tab";
    }

    elseif (loc =="US") {

    window.location = "hxxp://mysite.com/index.htm#us-tab";
    }

    elseif (loc =="AU") {

    window.location = "hxxp://mysite.com/index.htm#au-tab";
    }

    else { // default url if no country code matches
    window.location = "hxxp://mysite.com/index.htm";

    }
    -->

    </script>
    Last edited by slotplayer; 11 April 2016 at 4:59 pm.

  3. #3
    baldidiot is offline Private Member
    Join Date
    January 2010
    Posts
    4,253
    Thanks
    403
    Thanked 1,948 Times in 1,280 Posts

    Default

    Ok cool, cheers.

    I'm slightly apprehensive to rely on an external service for this - is it pretty reliable?

    My knowledge of javascript is very minimal but looks like it's taking the country reference and storing it as a javascript parameter? Guessing we could do that with an internal country detection, so long as we make the country code available correctly?
    onlinegamblingwebsites.com - Formally known as goodbonusguide.
    baldidiot.net - Baldys affiliate blog. Will get updated one day. Maybe.

  4. #4
    slotplayer is offline Private Member
    Join Date
    September 2006
    Posts
    1,038
    Thanks
    194
    Thanked 323 Times in 252 Posts

    Default

    Well the best way is to install maxmind on your host, but that is a little complex.
    The Geo plugin site using maxmind lite and returns a bunch of information on the visitor.

    It seems reliable but how long will the site and script be around is anyone's guess. My test file is dated July 2015 so its been around at least that long.

    You can seen all the visitor info geo plugin returns:
    http://www.geoplugin.com/quickstart#..._your_visitors

    All you do is put the geo plugin script between the head tags.
    Then use js to call any of the geoplugin functions.
    I called the country_code with this line: var loc = geoplugin_countryCode();
    now my var loc contains the country code of the visitor and from there I can decide what to do.

    When I used it I sent the visitor to an entirely different url, (a sorry page) so it worked for that.

    However, now that I look at it closer I'm not sure that a js hash tag script idea will work to open tabs on the same page without testing it because it could get stuck in a loop. It might have to be a server side (php) script. (js is browser side, ie.. client side) or js that manipulates some css.

    The reason is you only want to get the visitor country code once. A hash tag php script would do that because php is run before the browsers receives the page.

    Consider this, someone visits the site from a search engine, the browser runs the js scripts the first time, gets the visitor country code and then changes the url to the one with a hash tag (via window.location), the browser might reload the site which in turn re-runs the js scripts only to repeat the process over and over again, thus a loop.

    The js version has to be tested to see its behavior.

  5. #5
    baldidiot is offline Private Member
    Join Date
    January 2010
    Posts
    4,253
    Thanks
    403
    Thanked 1,948 Times in 1,280 Posts

    Default

    Thanks for the input.

    I'm actually quite comfortable with server side geotargetting and can get hold of the users country, so that's not the tricky bit. It's doing it on the the browsers side that I'm not sure about...

    So assuming we've defined the country code and made it available on the page, it's the next step where we select the tab that I haven't a clue about.
    onlinegamblingwebsites.com - Formally known as goodbonusguide.
    baldidiot.net - Baldys affiliate blog. Will get updated one day. Maybe.

  6. #6
    slotplayer is offline Private Member
    Join Date
    September 2006
    Posts
    1,038
    Thanks
    194
    Thanked 323 Times in 252 Posts

    Default

    I'm not familiar with jquery but I'm sure other members are.

    My guess is to use country code to set/modify the jquery active option using an if/else statement.
    https://api.jqueryui.com/tabs/#option-active

Posting Permissions

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