Forum Moderators: open
To define geotargeting and language redirection:
Geotargeting - redirecting internet surfers based on their geographic location - showing different web pages to people in different gerographical locations (eg. countries).
language redirection - Redirects a user to the page based on their language. For example, English language user browsers, which report the language as 'en' in most cases, can be redirected to an English page, while Spanish language user browser, which report the language as 'es' in most cases, can be sent to a separate Spanish page.
I want to set up some code that has the following kind of architecture:
if (country = France AND language = French) redirect = url 1
else if (country = USA AND language = Spanish) redirect = url 2
else if (country = USA AND language = Portugese) redirect = url 3
else if .......
else
So, you can see how I want to integrate the geographical and language information.
BUT - has javascript got such an AND command as I use above? I have read about if - else conditionals - but I have never come accross the possibility of an AND command. But such a command is the kind of thing that I want to do here. I want to redirect on the basis of geography AND language.
So - I currently have a 1) language redirection javascript and a 2) geodirection javascript - that I want to integrate. These are listed below.
I would be ever so grateful for some help.
1) LANGUAGE REDI¦RECTION script
From: [javascript.internet.com...]
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;
if (language.indexOf('en') > -1) document.location.href = 'English.html';
else if (language.indexOf('nl') > -1) document.location.href = 'dutch.html';
else if (language.indexOf('fr') > -1) document.location.href = 'french.html';
else if (language.indexOf('de') > -1) document.location.href = 'german.html';
else if (language.indexOf('ja') > -1) document.location.href = 'japanese.html';
else if (language.indexOf('it') > -1) document.location.href = 'italian.html';
else if (language.indexOf('pt') > -1) document.location.href = 'portuguese.html';
else if (language.indexOf('es') > -1) document.location.href = 'Spanish.html';
else if (language.indexOf('sv') > -1) document.location.href = 'swedish.html';
else if (language.indexOf('zh') > -1) document.location.href = 'chinese.html';
else
document.location.href = 'English.html';
// End -->
</script>
2) GEODIRECTION javascript
From: [geobytes.com...]
GeoDirection is a free service that dynamically redirects internet surfers based on their geographic location. This JavaScript redirection tool is ideal for internet users that wish to redirect browsers based on their City, Region or Country, using Geobytes' IP Address map technology. See the geobytes geodirection website for more (url is above).
Geodirection code example to redirect users from multiple countries to multiple pages (for other geolocation code examples - please see the geodirection website)
<head>
<script language="Javascript" src="http://gd.geobytes.com/Gd?after=-1"></script>
<script language="javascript">
var sSpanishLocations="ES,MX,GT,SV,HN,NI,CR,EC,PE,CU,DO,PR,PA,VE,CO,BO,AR,CL,PY,UY";
var sGermanLocations="DE,AT,CH";
var sFrenchLocations="FR,BE";
var sPhilippineLocations="PH";
var sKoreanLocations="KP,KR";
var sChineseLocations="CN";
if(typeof(sGeobytesLocationCode)!="undefined")
{
var sCountryCode=sGeobytesLocationCode.substring(0,2);
if(sCountryCode!="US"&&sCountryCode!="CA")
{
if(sSpanishLocations.indexOf(sCountryCode)>=0)
{
// Spanish Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Spanish.htm'>");
}else if(sGermanLocations.indexOf(sCountryCode)>=0)
{
// German Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=German.htm'>");
}else if(sFrenchLocations.indexOf(sCountryCode)>=0)
{
// French Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=French.htm'>");
}else if(sPhilippineLocations.indexOf(sCountryCode)>=0)
{
// Philippine Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Philippine.htm'>");
}else if(sKoreanLocations.indexOf(sCountryCode)>=0)
{
// Korean Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Korean.htm'>");
}else if(sChineseLocations.indexOf(sCountryCode)>=0)
{
// Chinese Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Chinese.htm'>");
}else
{
// World Visitors would go here
document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=World.htm'>");
}
}
}
</script>
</head>
[geobytes.com...]
Yes it does, &&: if (condition1 && condition2) ...
Btw, did you read the terms & conditions [geobytes.com] of that service?
For approximately every 1 in 50 GeoPhrase requests served the current browser window will be directed to the Geobytes site or that of a sponsor. Simultaneously a new window will be opened for the original, intended content.
If possible, I'd go for a server-side solution.
if (language = French AND country = USA) redirect = url1
else if (language = French AND NOT country = USA) redirect url = 2
else if.....
else
To elaborare
if the browser language is French and the user is in the USA redirect url = 1
if the browser language is French and the user is NOT in the USA redirect =url 2
Would really appreciate some help with this - would be ever so grateful. If I can do such a thing as this AND NOT command I really think that I will be cracking.
As an aside - I am still very interested if anyone knows an AND-NOT syntax in javascript. It would really be great to hear anything on this.
<script language="Javascript" src="http://gd.geobytes.com/Gd?after=-1"></script>
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
// if .language exists, use it. otherwise, use .browserLanguage
var language = navigator.language ¦¦ navigator.browserLanguage;
switch(language + sGeobytesLocationCode) {
case "enUSA":
default:
redirect = 'English.html';
break;
case "esUSA":
redirct = 'spanish.html';
break;
case "frUSA":
redirct = 'french.html';
break;
/*
the following example shows how to set up multiple country/language combinations, as there will be more than one combination pointing to each page. for example, the following two account for German language, USA, and German language, Germany, respectively.
*/
case "deUSA":
case "deDE":
redirct = 'german.html';
break;
}
window.location.href = redirect;
</script>
if (a == 2 && b!= 3) ...
The!= operator means 'not equal to'.
'default' should be at the end of your switch block.
Anyway, this forum wasn't created to fix everybody's code. Why not buy a JavaScript book that explains these very basic things?