互联网科技让前端飞码农的世界

前端JavaScript-获取浏览器的所使用语言

2019-05-15  本文已影响3人  560b7bb7b879

本章节分享一段代码实例能够获取当前浏览器所使用的语言,比如使用的简体中文还是使用的其他语言。

代码实例如下:

var language=navigator.browserLanguage?navigator.browserLanguage:navigator.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 = 'http://www.softwhy.com'; 
else
document.location.href='english.htm';

代码非常的简单这里就不多介绍了.web前端学习交流扣qun:731771211 志同道合者进!

上一篇 下一篇

猜你喜欢

热点阅读