1
不工作,我有一個下拉列表,當在它 語言的用戶點擊它調用一個js函數更改地區 在Firefox 工作正常,但在Chrome它不「T在所有的工作,我不知道爲什麼更改用戶的語言環境中鉻
列表:
<select name="languageMenu" >
<option selected="selected" ><fmt:message key="language.languages" /></option>
<option value="en" onclick="switchLocale('en');"><fmt:message key="language.English"/></option>
<option value="ar" onclick="switchLocale('ar');" ><fmt:message key="language.Arabic"/></option>
</select>
JS:
<script type="text/javascript">
function switchLocale(lang_opt) {
var selected = lang_opt.selectedIndex;
//var locale = lang_opt.options[selected].value;
var locale = lang_opt;
var href = document.location.href;
if (href[href.length - 1] === "#") {
href = href.substr(0, href.length - 1); // -1 removes "#"
}
var newHref = "";
if (document.location.search.length > 0) {
var langParamIndex = href.indexOf("lang");
if (langParamIndex > -1) {
newHref = href.substr(0, langParamIndex);
newHref += "lang=" + locale;
newHref += href.substr(langParamIndex + "lang=zz".length);
} else {
newHref = href + "&lang=" + locale;
}
} else {
newHref = href + "?lang=" + locale;
}
document.location = newHref;
}
</script>
您是否嘗試過更改最後一行,以便設置'document.location.href'而不是'document.location'?只是一個猜測。 – Pointy 2011-06-11 11:53:35
嘗試過,謝謝。 – 2011-06-11 15:27:05