Forum Moderators: open
I need to add code to load a new page when a language is selected - it's the same page for all languages.
Any way to modify this code to add the page reload?
Thanks!
Terry
<form action="" method="post" name="languageform" id="languageform">
<img src="/images/flag_us.png" class="img-navflag" name="flag_img"/>
<select id="lang_user" onchange="javascript:processCookie()" name="lang_user">
<option value="en-us">ENGLISH</option>
<option value="de-at">DEUTSCH</option>
</select>
<script type="text/javascript" language="javascript">
var flag_img_arr=new Array();
flag_img_arr[0]="/images/flag_us.png"
flag_img_arr[1]="/images/flag_germany.png"
tl = getCookie("lang_cookie");
for(i=0;i<6;i++){
if(tl==document.languageform.lang_user.options[i].value){
document.images.flag_img.src=flag_img_arr[i];
document.getElementById("lang_user").selectedIndex=i;
}
}//for
</script>
</form>
But this comes close:
<select id="lang_user" onchange="javascript:processCookie();window.location.replace('page.html')" name="lang_user"
This loads page.html in the current language - but displays the new language in the drop down. Then on reload, or navigating to any other page, it displays the page in the new language.
It sets the cookie but doesn't read it until a reload.
Any thoughts?
Thanks!
Terry
The processCookie() function now looks like this:
function processCookie(){
document.languageform.submit();
lang=document.languageform.lang_user.value;
delCookie('lang_cookie');
setCookie('lang_cookie',lang,'1');
window.location.href="newpage.html";
}
Which works - almost.
When a new language is selected, it sets the cookie and loads newpage.html in that language.
However, the next page navigated to loads in the old language.
But a reload of that page displays the new language - and all subsequent pages are in the new language.
Any thoughts on what might be going on?
Thanks a lot!
Terry
it's the same page for all languages
If the browser has one of your pages cached say widget.html in english, then future requests for widget.html will get this page even if the cookie has changed.
Either use different urls per language, (eg widget.html?lang=eng) or on page load check page is in correct language else reload.