Heim  >  Artikel  >  Backend-Entwicklung  >  自动跳转中英文页面

自动跳转中英文页面

WBOY
WBOYOriginal
2016-06-20 13:05:19807Durchsuche

当来访者浏览器语言是中文就进入中文版面
国外的用户默认浏览器不是中文的就跳转英文页面
PHP 网页根据来访这的浏览器语言不同自动跳转中英文页面

PHP代码:<br /><?php<br />$lan = substr($HTTP_ACCEPT_LANGUAGE,0,5);<br />if ($lan == "zh-cn")<br />print("<meta http-equiv='refresh' content = '0;URL = gb/index.htm'>");<br />else<br />print("<meta http-equiv='refresh' content = '0;URL = eng/index.htm'>");<br />?>

JS脚本根据来访这的浏览器语言不同自动跳转多语言页面

var type=navigator.appName<br />if (type=="Netscape")<br />var lang = navigator.language<br />else<br />var lang = navigator.userLanguage<br />//cut down to first 2 chars of country code<br />var lang = lang.substr(0,2)<br />// 英语<br />if (lang == "en")<br />window.location.replace('url')<br />// 简体中文<br />else if (lang == "zh-cn")<br />window.location.replace('url')<br />// 繁体中文<br />else if (lang == "zh-tw")<br />window.location.replace('url')<br />// 德语<br />else if (lang == "de")<br />window.location.replace('url')<br />// 除上面所列的语言<br />else<br />window.location.replace('url')


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn