Forum Moderators: open

Message Too Old, No Replies

geotargeting and language redirection javascript

         

rhodopsin

8:34 pm on Oct 20, 2004 (gmt 0)

10+ Year Member



I wish to combine (weave together) a geotargeting javascript and a language redirection javascript.

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>

rhodopsin

8:42 pm on Oct 20, 2004 (gmt 0)

10+ Year Member



In the post above I have realised that the geodirection javascript may be a bit difficult to follow - but it becomes a lot more clear after looking at the home website of this script.

[geobytes.com...]

RonPK

11:02 am on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> has javascript got an AND command?

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.

rhodopsin

7:20 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Thanks heaps mate. Great to discover about the AND command.

Sorry to rock the boat but can I ask whether javascript has an AND NOT command?

if (condition 1 AND NOT condition 2) {execute}

That is condition 1 is satisfied and condition 2 is not satisfied.

rhodopsin

7:40 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



To elaborate with some pseudocode

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.

rhodopsin

10:02 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



To go back to the AND issue. You very kindly let me know && as the AND command in javascript. Below is some javascript that a friend gave me that implements another method of AND in javascript. I thought i would put it here for your interest - I can;t actually get it to work myself. I don;t know why it isn;t working - I have asked the friend and am waiting for him to get back to me. I will post as soon as I hear back.

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>

RonPK

8:04 am on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In JavaScript there is no such thing as AND NOT. But this has the same effect:

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?