html根据电脑系统语言自动跳转到对应语言的网页代码

有时候我们做外贸网站几个语言,国外用户访问国外语言,大陆用户访问中文界面,这个时候一般我们会考虑到用IP库来识别,但是对于我们一般小站不切实际。这时候我们用最简单的一个js代码就可以实现,根据调用访问用户的电脑系统来判断。

<script type="text/javascript">  
 
var type=navigator.appName;  
if (type=="Netscape") var lang = navigator.language;  
else var lang = navigator.userLanguage;  
 
//cut down to first 2 chars of country code  
var lang = lang.substr(0,2);  
 //英语  
if(lang == "en") window.location.replace('http://www.um80.cn/en');  
 //中文(不管简体繁体)  
else if (lang == "zh") window.location.replace('http://www.um80.cn/cn');  
//德语  
else if (lang == "de") window.location.replace('http://www.um80.cn/en');  
 //除上面所列的语言  
else window.location.replace('http://www.um80.cn/en');  
</script> 

原文链接:https://www.um80.com/1487.htm,转载请注明出处。

1
金秋上云特惠新人专享

评论0

本站所有素材,站长均亲自测试过,可放心使用,有什么问题联系我们!18091738064(微信)

社交账号快速登录

Copyright   ©2017-2021  U码80  陕ICP备17013443号-1  

陕公网安备 61032402000158号