2013-02-24 106 views
0

我想根据访问者的IP地址重定向,我有下面的代码,经过测试,但它总是去AU,其他所有其他地方如果条件不起作用,请大家帮忙,谢谢.. 。根据访问者的IP地址重定向ip

<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script> 
<script language="Javascript"> 
    var mylocation=geoplugin_countryCode(); 
    if (mylocation=="AU") { 
    window.location.href='http://www.propertyhere.com/Country/AU/search-to-buy'}, 
    else if (mylocation=="CA") { 
    window.location.href='http://www.propertyhere.com/Country/CA/search-to-buy'}, 
    else if (mylocation=="CN") { 
    window.location.href='http://www.propertyhere.com/Country/CN/search-to-buy'}, 
    else if (mylocation=="NZ") { 
    window.location.href='http://www.propertyhere.com/Country/NZ/search-to-buy'}, 
    else if (mylocation=="RU") { 
    window.location.href='http://www.propertyhere.com/Country/RU/search-to-buy'}, 
    else if (mylocation=="US") { 
    window.location.href='http://www.propertyhere.com/Country/US/search-to-buy'}, 
    else if { 
    window.location.href='http://www.propertyhere.com/network'}, 
</script> 
+0

重定向这样对于服务器端更适合,在页面和脚本加载之前。你有没有用AU以外的计算机来测试它,并通过控制台日志记录来检查你的geoplugin实际返回的结果?另外,你有语法错误? – adeneo 2013-02-24 14:57:05

回答

1

检查您的if语句 - 看起来像你需要采取的逗号出你的别人-IF的并用分号替换:

if (mylocation=="AU") { 
window.location.href='http://www.propertyhere.com/Country/AU/search-to-buy'; 
} else if (mylocation=="CA") { ... 
+0

另外,在行尾使用逗号并使用分号。 – 2013-02-24 14:57:55