js 判断浏览器语言的代码

发布时间:2020-07-04编辑:脚本学堂
本文介绍了js 判断浏览器使用语言的一段代码,用js脚本获取浏览器相关信息,感兴趣的朋友参考下。

例子,js获取浏览器使用的语言信息。
 

复制代码 代码示例:
<script type="text/javascript">
var language = navigator.browserLanguage?navigator.browserLanguage:navigator.language;
alert(language);
if (language.indexOf('en') > -1) document.location.href = 'english.htm';
else if (language.indexOf('nl') > -1) document.location.href = 'dutch.htm';
else if (language.indexOf('fr') > -1) document.location.href = 'french.htm';
else if (language.indexOf('de') > -1) document.location.href = 'german.htm';
else if (language.indexOf('ja') > -1) document.location.href = 'japanese.htm';
else if (language.indexOf('it') > -1) document.location.href = 'italian.htm';
else if (language.indexOf('pt') > -1) document.location.href = 'portuguese.htm';
else if (language.indexOf('es') > -1) document.location.href = 'Spanish.htm';
else if (language.indexOf('sv') > -1) document.location.href = 'swedish.htm';
else if (language.indexOf('zh') > -1) document.location.href = 'chinese.htm';
else // www.jb200.com
document.location.href = 'english.htm';
</script>