2

I have this script to get the language of the browser and open the specific index localized

       var language = window.navigator.systemLanguage;

if (language == "it-IT" || language == "it-it" || language == "ita-IT" || language == "it-ITA" || language == "it" ||language == "IT" ||language == "ita" ||language == "italiano" || language == "italian")
{
    location.href = "index_it.html";
}
else{
    location.href = "index_esp.html";
}

unfortunately works only in Internet Explore but in Firefox and Chrome switch always on index_esp.html also with Italian Browsers

How to get the right language String ID? (If is this the cause of the issue)

AndreaF
  • 11,975
  • 27
  • 102
  • 168

1 Answers1

1

You can try both "systemLanguage" and "language":

var language = window.navigator.systemLanguage || window.navigator.language;

It'd make your life easier to convert it to lower case too:

language = language.toLowerCase();
Pointy
  • 405,095
  • 59
  • 585
  • 614
  • thanks! Seems that In IE works only `systemLanguage` and in the other browsers `language`, otherwise the id of the language results undefined – AndreaF Aug 12 '13 at 16:01