跳到主要内容

自动跳转中英文页面代码

冰客 冰客 2008-11-7 14:40:55 9471 阅读
发表于 2008-11-7 14:40:55 | 显示全部楼层 |阅读模式
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>
复制代码
您需要登录后才可以回帖 登录 | 成为会员 微博登录

本版积分规则

标签云|小黑屋|科技先生

Powered by Discuz! X5.0 © 2001-2026 科技先生|京ICP备07036130号

在本版发帖返回顶部