Help with language redirect

Discussion in 'JavaScript' started by ththth12, Dec 5, 2007.

  1. #1
    Hi!
    I need some help with language redirecting. I have site in my own language(finnish), and in english. Both sites are under different domain names. Because finnish version is older it gets lot of international traffic trough search engines, and I would like to direct all of that automatically to my english version.

    I used javascript code I found, and put it into index page of finnish version. Traffic was redirected alright, but for some reason, browsers in finnish language began to loop, and reload page constantly. There must be some way to fix it, but I'm just beginning to learn javascript, and have no idea how to do it.:eek:

    I also wonder if there is way do it better, and redirect all languages except finnish to english version. Code would at least be shorter. Any help in this would be great, too.:p

    This is code I found:

    <script>
    /*
    Browser Language Redirect script- By JavaScript Kit
    For this and over 400+ free scripts, visit http://www.javascriptkit.com
    This notice must stay intact
    */

    var langcodes=new Array("en", "fr", "es", "ja", "zh", "default")

    var langredirects=new Array("index.htm", "french.htm", "spanish.htm", "japan.htm", "chinese.htm", "index.htm")

    var languageinfo=navigator.language? navigator.language : navigator.userLanguage
    var gotodefault=1

    function redirectpage(dest){
    if (window.location.replace)
    window.location.replace(dest)
    else
    window.location=dest
    }

    for (i=0;i<langcodes.length-1;i++){
    if (languageinfo.substr(0,2)==langcodes){
    redirectpage(langredirects)
    gotodefault=0
    break
    }
    }

    if (gotodefault)
    redirectpage(langredirects[langcodes.length-1])
    </script>
     
    ththth12, Dec 5, 2007 IP