Automatic Language Selection by IP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m9817232
    New Member
    • Mar 2008
    • 8

    Automatic Language Selection by IP

    I applied the code as mentioned in:
    http://javascript.abou t.com/library/bllang.htm


    so when a Dutch-speaking visitor (nl being the ISO-code for Dutch language) visits my site, he should automaticly be redirected to the index-nl.htm page

    but what it returns is:
    www.mywebsite-nl.com

    instead of:
    www.mywebsite.c om/index-nl.htm

    can someone please adapt to make it work?

    many thx!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    here is an example:

    [CODE=javascript]
    var langCode = navigator.langu age || navigator.syste mLanguage;
    var lang = langCode.toLowe rCase();
    lang = lang.substr(0,2 );

    var dest = window.location .href;
    var re = /(.\w+)$/;
    var ext = dest.match(re)[1];
    dest = dest.replace(re , '-' + lang) + ext;
    [/CODE]
    that simply assumes that your start-page is 'index.html' ...

    kind regards

    Comment

    Working...