目前測試正確顯示方式為php , 可解決語系優先順序
javascript 語法
if (navigator.appName == 'Netscape')
var language = window.navigator.language;
else
var language = window.navigator.browserLanguage;
var hrefPage = "en/index.htm";
if (language.toLowerCase().indexOf('tw') > -1) hrefPage = "tw/"; //繁體中文
if (language.toLowerCase().indexOf('en') > -1) hrefPage = "en/"; //英文
if (language.toLowerCase().indexOf('ja') > -1) hrefPage = "ja/"; //日本
location.href = hrefPage ;
php 語法
$lang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$url = "tw/" ;
if( strpos( '.' .$lang[0] , 'tw' ) ) {
$url = "tw/" ;
}else if ( strpos( '.' .$lang[0] , 'en' ) ) {
$url = "en/" ;
}
echo '<script type="text/javascript">location.href = \''. $url. '\';</script>';
沒有留言:
張貼留言