-2
I’m trying to load a page by satisfying a condition and with the code I did loads but enters an eternal loop. I have already researched and tried everything I saw but I did not get the expected result. If anyone can help me. This code is on the same page that I want to translate.I thank you in advance for the attention.
<script>
$(window).ready(function(){
if(pais === 'brazil'){
document.location = 'minhaurl.com?language=portuguese';
}
else{
document.location = 'minhaurl.com?language=english';
}
});
</script>
Do you understand why you are entering the loop? What result awaits?
– MagicHat
If this code is in the index of
minhaurl.com
, then when loading the page, it runs the script, which arrow Location to minhaurl.com, which runs the script, which arrow Location to minhaurl.com, which runs the script, which arrow Location to minhaurl.com and so on...– hkotsubo
@Magichat I hope it loads once.
– Ana Carolina
@hkotsubo So this I understood but how I could solve?
– Ana Carolina
This is happening because you are using a relative url, put
http://
orhttps://
before the domain. After that you may have more to debug, because it is not clear where the value ofpais
.– bfavaretto
"how could I solve?" - Depends, where does the variable come from
pais
? How/when should I show a particular language? It is the user who chooses, it is some other action of the system that defines it? etc etc etc etc... Without knowing this, any solution will be kick - as the answer below, for example, because it is not possible to know if the situation below applies (if it is to set thelanguage
only if it does not exist, or if it can overwrite an existing one, etc.). Could [Dit] the question clarifying these points?– hkotsubo