2

我有这个脚本来获取浏览器的语言并打开本地化的特定索引

       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";
}

index_esp.html不幸的是,仅在 Internet Explorer 中有效,但在 Firefox 和 Chrome 中,意大利浏览器也始终打开

如何获得正确的语言字符串 ID?(如果这是问题的原因)

4

1 回答 1

1

您可以同时尝试“systemLanguage”和“language”:

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

将其转换为小写也会使您的生活更轻松:

language = language.toLowerCase();
于 2013-08-12T15:53:56.667 回答