window.location =“保持当前站点”

时间:2011-09-06 13:49:40

标签: javascript redirect

我希望所有非EN的访问者都能被重定向,但来自EN的访问者应该留在网站上。是否有命令?

    <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>


<script language="JavaScript">

var country= geoip_country_code();

if(country  == "EN")      
{
<!--
window.location = "STAY ON SITE"
//-->
}

else   
{
<!--
window.location = "https://www.sample.com/"
//-->
}

</script>

3 个答案:

答案 0 :(得分:3)

请勿设置window.location,它将保留在网站上。

答案 1 :(得分:1)

如果country == "EN",请不要做任何事情。

if (country !== "EN")
    window.location = "https://www.sample.com/"

答案 2 :(得分:0)

您可能应该使用浏览器区域设置来确定信息。快速谷歌搜索提供了这个脚本:

if ( navigator ) {
if ( navigator.language ) {
    return navigator.language;
}
else if ( navigator.browserLanguage ) {
    return navigator.browserLanguage;
}
else if ( navigator.systemLanguage ) {
    return navigator.systemLanguage;
}
else if ( navigator.userLanguage ) {
    return navigator.userLanguage;
}

}

除此之外,我会在服务器端实现这种行为,恕我直言。当然,如果区域设置是所需的区域,则不必设置窗口位置。