简体   繁体   中英

Redirect page using javascript

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>

Concatenate the string:

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

window.location.href="http://yourwebsite.com/currentpage?lang=" + language;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM