通过代码改变客户端所显示的语言类型
2007-11-27 16:16:33 来源:WEB开发网使用这断代码自动查明客户端浏览器的语言类型,重新定向语言类型
<script>
file://Enter ISO 639-2 letter Language codes to detect (see: http://www.w3.org/WAI/ER/IG/ert/iso639.htm):
var langcodes=new Array(en, fr, es, ja, zh, default)
file://Enter corresponding redirect URLs (last one is for default URL):
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[i]){
redirectpage(langredirects[i])
gotodefault=0
break
}
}
if (gotodefault)
redirectpage(langredirects[langcodes.length-1])
</script>
更多精彩
赞助商链接