Reputation: 39
I have question,I want to redirect page using javascript which the code is to detect country id.After I looking it on google,I found a way to do it.
on the html in <head>
tag,I insert the window.location = language,language is variable that will detect country id from geoapi_country_code
here's the code.
var language = geoapi_country_code();
here's the problem,when I use the variable in the window.location,it doesn't work but if I put normal string it works. my question,is my way to redirect is correct or there's another way to do it?please explain it to me thanks in advance
I have tried with window.location.href and it works but now here comes another problem,after the web redirect,it's not stopping but redirect again and again how do I stop that?
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">
var language = geoip_country_code();
if(language == "ID")
{
window.location.href= "<?php echo $this->rootUrl(); ?>" + '/' + language.toLowerCase() ;
}
else
{
window.location.href = "http://localhost/lamanbudaya/public/en";
}
</script>
Upvotes: 0
Views: 3741
Reputation: 14419
Concatenate the string:
var language = geoapi_country_code(); //lets say language is en_US
window.location.href="http://yourwebsite.com/currentpage?lang=" + language;
Upvotes: 1