This topic created in 888 days ago, the information mentioned may be changed or developed.
AI 给了这样的代码:
<script>
var lang = (navigator.language || navigator.userLanguage).toLowerCase();
switch (lang) {
case 'it':
window.location.href = 'it.html';
break;
case 'de':
window.location.href = 'de.html';
break;
case 'ja':
window.location.href = 'ja.html';
break;
case 'zh-cn':
window.location.href = 'zh-cn.html';
break;
case 'zh-tw':
window.location.href = 'zh-tc.html';
break;
case 'zh-hk':
window.location.href = 'zh-tc.html';
break;
default:
window.location.href = 'en.html'; // Default to English if no match found
}
</script>
我的疑问是,我通过 chrome 调试,选了 Tokyo ,它语言是 ja-JP ,那么这个 ja-JP 不会跳转 ja.html?
那么其他如 de-DE 也不会跳转 de.html ?那我岂不是还得收集全部的 de-XX 和 ja-XX 都写入这个代码?
 |
|
1
AoEiuV020JP Nov 22, 2023 1
那就别用 switch , 用 if startsWith 之类的判断条件,或者干脆 split 分成两个部分分别判断,
|
 |
|
2
CSGO Nov 23, 2023
@ AoEiuV020JP OK if (lang.startsWith('ja')) { window.location.href = 'ja.html'; break; }
|