Hello,
I have two scripts that do what I want, but I need to combine them. Basically if there is a cookie for "US" then it let's the user browse the US site. However if no cookie exists then I want it to run the Geo redirect based on location. They both work on there own but I can not for the life of me get it to do the cookie part first then if no cookie exists run the geo redirect. Any Help would be massively huge. Thanks.
Here is my 2 separate scripts:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="Javascript" type="text/javascript">
<!--
function ReadCookie() {
var NameOfCookie="Language";
if(document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if(begin != -1)
{
// our cookie was set.
// The value stored in the cookie is returned from the function
begin += NameOfCookie.length + 1;
end = document.cookie.indexOf(";",begin);
if(end == -1) end = document.cookie.length;
language=(document.cookie.substring(begin,end));
if (language==="US")document.location.href='http://www.site.com';
}
}
}
function SetCookie(cookieName,cookieValue) {
var today = new Date();
var expire = new Date();
var nDays=365
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue)
+ ";expires="+expire.toGMTString();
}
//-->
</script>
<script language="Javascript" type="text/javascript">
function GetGeo() {
var country = geoip_country_code();
if(country=="GB")
{
window.location = "http://uk.site.com"
}
else if(country=="FR")
{
window.location = "http://fr.site.com"
}
}
</script>
Then I do body onload = ReadCookie()