By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

Showing script based on the country

P: n/a
I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?
Jul 4 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Nospam wrote:
I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?

You can't do it reliably. All you can do is take a guess at the country of the
ip connecting to you, and that won't always be accurate. Plus they might be
using a proxy anyplace in the world.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 4 '06 #2

P: n/a
On Mon, 03 Jul 2006 22:22:08 -0400, Jerry Stuckle put finger to
keyboard and typed:
>Nospam wrote:
>I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?


You can't do it reliably. All you can do is take a guess at the country of the
ip connecting to you, and that won't always be accurate. Plus they might be
using a proxy anyplace in the world.
That's true, but it's not quite as bad as you make it sound. Freely
available Geo-IP databases will give over 95% accuracy, which is
usually enough for most purposes. Proxies aren't really a major issue,
as almost all well-configured proxies will pass the originating IP on
in the HTTP-FORWARDED-FOR header. Those that don't are generally those
which are deliberately designed to anonymise the origin, and that's
fairly rare.

The main problem is AOL, which will always appear as the US
irrespective of the user's actual location, as AOL configures all its
worldwide addresses from the same US-allocated pool. To get accurate
geo-location of AOL users, therefore, you need access to AOL's
internal database, and that isn't available for free. Some commercial
products include it (as well as other ISP cross-border databases), and
with that level of detail you can get over 99% accuracy - provided
you're prepared to pay for it.

To go back to the OP's question, Geo-IP detection is best done
server-side using a combination of scripting and a database, as you're
going to need to cross-check against a quite large amount of data.
It's pretty trivial with most server-side scripting/database
combinations, such as PHP/MySQL or ASP/MSSQL, but you do need a
certain familiarity with these in order to use them. If you don't want
to run your own database, I'd suggest using the freeware binary data
from MaxMind, together with one of their supplied APIs in the
scripting language of your choice:

http://www.maxmind.com/app/geoip_country

Mark
--
Visit: http://names.orangehedgehog.com - British surname distribution profiles
Listen: http://www.goodge.co.uk/files/dweeb.mp3 - you'll love it!
Jul 4 '06 #3

P: n/a
To further the education of mankind, Jerry Stuckle
<js*******@attglobal.netvouchsafed:
Nospam wrote:
>I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?


You can't do it reliably. All you can do is take a guess at the
country of the ip connecting to you, and that won't always be
accurate. Plus they might be using a proxy anyplace in the world.
Yeah. One time I used a proxy in Biloxi to chat with some foxy with the
moxie in Bayonne...

--
Neredbojias
Infinity has its limits.
Jul 4 '06 #4

P: n/a
JRS: In article <Gv******************************@comcast.com>, dated
Mon, 3 Jul 2006 22:22:08 remote, seen in news:comp.lang.javascript,
Jerry Stuckle <js*******@attglobal.netposted :
>Nospam wrote:
>I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?
>You can't do it reliably. All you can do is take a guess at the country of the
ip connecting to you, and that won't always be accurate. Plus they might be
using a proxy anyplace in the world.
Plus it may not be relevant. A substantial proportion of people
hereabouts, both in this district and in this building, are of non-UK
origin and may well prefer to be treated as if in another country.

Then many of those using Internet cafes are just passing through the
area.

If you are required to be selective, then javascript is not the tool,
and the task may be impossible; otherwise, let the user choose.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 4 '06 #5

P: n/a
Nospam <no****@home.comscripsit:
I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?
Why would you _show_ a certain script?

In almost all cases like this, an analysis of the problem reveals that it's
not really about country but language. So the problem definition is wrong,
and we don't even need to consider all the pitfalls in solving the wrong
problem.

In any case, telling the _real_, original problem and illustrating it with a
URL would at least give you a working chance of getting a useful solution.

F'ups trimmed.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jul 4 '06 #6

P: n/a
Nospam schrieb:
I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?

Another solution would be to write everything in one script but call
different functions according to the language. The advantage would be
that you can use JS to get the language selected in the browser:

var lang;
if (navigator.browserLanguage) lang=navigator.browserLanguage; //IE
else if (navigator.language) lang=navigator.language; //others

or, shortend:

var lang=(navigator.browserLanguage) ? navigator.browserLanguage :
navigator.language;
Jul 5 '06 #7

P: n/a
jojo <jo*********@gmx.descripsit:
Nospam schrieb:
>I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?

Another solution would be to write everything in one script but call
different functions according to the language.
Solution to what? Surely not to the question that was asked, though perhaps
to the question that the OP _meant_ to ask. It's probably still the wrong
question.
The advantage would be
that you can use JS to get the language selected in the browser:
No, it is a definite _disadvantage_, since now you would not even try to
select the user's preferred language but the language of the browser's
interface. This language is very often English even though the user knows
just a little English and prefers quite other languages. The simple reason
is that many browsers (especially new versions) are available as English
versions only.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jul 6 '06 #8

P: n/a
Jukka K. Korpela schrieb:
jojo <jo*********@gmx.descripsit:
>Nospam schrieb:
>>I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?

Another solution would be to write everything in one script but call
different functions according to the language.

Solution to what? Surely not to the question that was asked, though
perhaps to the question that the OP _meant_ to ask. It's probably still
the wrong question.
>The advantage would be
that you can use JS to get the language selected in the browser:

No, it is a definite _disadvantage_, since now you would not even try to
select the user's preferred language but the language of the browser's
interface. This language is very often English even though the user
knows just a little English and prefers quite other languages. The
simple reason is that many browsers (especially new versions) are
available as English versions only.
ASFAIK the JS-properties I suggested provide the language the user set
as his preferred language. In most browsers (IE, Firefox, Netscape,
Opera, ...) there is an option to select your preferred languages (_any_
language you like to, no matter in which language the browsers interface
is).
So it is even better using this properties than the IP because if, lets
say a German, is in the USA he has got an American IP. But perhaps he
still wants to view the websites in German...
Jul 6 '06 #9

P: n/a
jojo <jo*********@gmx.descripsit:

[ pointless fullquote - the usual signal of lack of comprehensive reading ]
ASFAIK the JS-properties I suggested provide the language the user set
as his preferred language.
"ASFAIK"? So you never actually tested it?
In most browsers (IE, Firefox, Netscape,
Opera, ...) there is an option to select your preferred languages
(_any_ language you like to, no matter in which language the browsers
interface is).
Yes. And this setting has, unfortunately, rather limited effect, since so
few servers try to make use of it. Besides, the setting is often wrong: it
reflects browser defaults rather than user preferences.

And the method you suggested does not fetch that setting but the browser's
interface language. Try it. Select any languages you like in the language
preferences and see what your code produces: not a string of language
preference list, or the first language in the list, or the language with the
highest quality factor. Instead, you get "en" if your browser interface is
English.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jul 8 '06 #10

P: n/a
You might want to considerIP2Location as well.

http://www.ip2location.com

Jul 29 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.