0

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>
2
  • have u tried alerting language variable? Commented Dec 10, 2012 at 4:23
  • Watch out, this can annoy many users. There are lots of people inside each country that prefer non-local languages by default. Commented Dec 10, 2012 at 4:32

1 Answer 1

1

Concatenate the string:

var language = geoapi_country_code(); //lets say language is en_US

window.location.href="http://yourwebsite.com/currentpage?lang=" + language;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.