techsir 登陆 |注册|TS首页
  首页 快活林 猿氏悟语

自动跳转中英文页面代码

By: 冰客 发表于 2008-11-7 14:40:55 · 6492次点击   回复:0   
PHP网页根据来访者的浏览器语言不同自动跳转中英文页面
当来访者浏览器语言是中文就进入中文版面
国外的用户默认浏览器不是中文的就跳转英文页面

PHP代码:

  1. <?
  2.    $lan = substr($HTTP_ACCEPT_LANGUAGE,0,5);
  3.    if ($lan == "zh-cn")
  4.          print("<meta http-equiv='refresh' content = '0;URL = gb/index.htm'>");
  5.    else
  6.          print("<meta http-equiv='refresh' content = '0;URL = en/index.htm'>");
  7. ?>
复制代码
HTML网页根据来访这的浏览器语言不同自动跳转多语言页面
在 之间加入如下代码:

  1. <script>
  2. var type=navigator.appName
  3. if (type=="Netscape")
  4. var lang = navigator.language
  5. else
  6. var lang = navigator.userLanguage

  7. //cut down to first 2 chars of country code
  8. var lang = lang.substr(0,2)

  9. // 英语
  10. if (lang == "en")
  11. window.location.replace('url')

  12. // 简体中文
  13. else if (lang == "zh-cn")
  14. window.location.replace('url')

  15. // 繁体中文
  16. else if (lang == "zh-tw")
  17. window.location.replace('url')

  18. // 德语
  19. else if (lang == "de")
  20. window.location.replace('url')


  21. // 除上面所列的语言
  22. else
  23. window.location.replace('url')

  24. </script>
复制代码
6492次点击
0个回复  |  直到 2008-11-7 14:40:55
添加一条新回复
您需要登录后才可以回帖 登录 | 成为会员 新浪微博登陆

标签云|手机版|科技先生 ( 京ICP备07036130号 Powered by Discuz! X )

GMT+8, 2024-5-19 15:26