I have an app where I am having a button on the top for page translation(english/spanish) & I hide them based on the page loaded. By default english loads, so the spanish button is on the top so the user can click on them, so the spanish version loads(we are hiding the spanish button and showing the english now).
The issue is when the user loads the page first time, then selects spanish, then goes away, then reloads the page, the spanish version comes off, but the button is spanish too. Technically it should be english. This is because the first time the page loads the value of the variable is undefined and it is defined as english and we show the spanish button. Is there anyway we can tweak this to display the buttons correctly? I also do not store anything in the cookie explicitly.
The code
function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
}
function pageLoadConditions() {
var lang = getUrlParameter('lang');
alert ("lang: " +lang);
if(typeof lang=="undefined"){
lang='en';
alert ("lang 2: " +lang);
}
alert ("lang 3: " +lang);
if(lang){
if(lang==="es"){
$('#lang_pref').val(lang);
$("#lang_ess").hide();
$("#lang_enn").show();
}else{
$('#lang_pref').val(lang);
$("#lang_enn").hide();
$("#lang_ess").show();
}
}else{
$('#lang_pref').val("en");
$("#lang_enn").hide();
$("#lang_ess").show();
}
}
window.onload = pageLoadConditions;
Thanks.