您的位置:首页 > 其它

浏览器语种检测,适合于多语言版本的站点

2008-04-30 08:23 381 查看
假如您的网站面向世界各地的冲浪者或对外开展商贸活动,检测来访者的浏览器语言类型就很现实了。这里提供

的脚本能够检测流露;浏览器的语言类型,一般中文能够识别为“zh”,英文版本的能够识别为“en”,然后根据判断的浏

览器语言类型导向不同语言版本的页面。当然您能够通过服务器端去解决这个问题,在客户端用这个脚本就能够了。

您需要将代码放在html的<head>区。然后做不同语言版本的页面即可。

<script language="javascript1.2">

<!--//

if (navigator.appname == netscape)

var language = navigator.language;

else

var language = navigator.browserlanguage;

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

document.location.href = english.htm;

// end -->

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: