473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Extracting just the country code from URL?

Laz
Hi,

I've not worked with javascript, and after searching could not find
example of this type of manipulation.

I'm trying to set a variable to the last portion of a domain name.
for example, if the URL is http://www.telefonica.es/index.php, I'd
like to get the "es" code into a variable.

Is there a predefined call for this?
Otherwise, what string manipulation libraries are available for this?

Thanks for any help,

Laz.
Jul 20 '05 #1
2 3999
Lee
Laz said:

Hi,

I've not worked with javascript, and after searching could not find
example of this type of manipulation.

I'm trying to set a variable to the last portion of a domain name.
for example, if the URL is http://www.telefonica.es/index.php, I'd
like to get the "es" code into a variable.

Is there a predefined call for this?
Otherwise, what string manipulation libraries are available for this?

var countryCode=location.host.replace(/^.*\./,"");

will give you whatever comes after the last "." in the domain name,
which may or may not be a country code.

Jul 20 '05 #2
Lee wrote:
Laz said:
Hi,

I've not worked with javascript, and after searching could not find
example of this type of manipulation.

I'm trying to set a variable to the last portion of a domain name.
for example, if the URL is http://www.telefonica.es/index.php, I'd
like to get the "es" code into a variable.

Is there a predefined call for this?
Otherwise, what string manipulation libraries are available for this?


var countryCode=location.host.replace(/^.*\./,"");

will give you whatever comes after the last "." in the domain name,
which may or may not be a country code.


Yeah, the OP should note that this method (and any other method) will
not always work. If it ends in .com or .edu or something like that,
then there is no country domain at the end to get, and you will get com
and edu.

Also, it will not work when running locally, off your drive, since there
is no location.host variable set. It also will not work on servers
without domain names... for instance, http://localhost/test.html or
http://SomePuterOnMyLocalNet/test.html will returh the host name in this
case, where the country code is not gotten, making testing a bit tough.

Just some thoughts,
Brian

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Avi | last post by:
hi, Can anyone tell me what the problem is and how to solve it The following piece of code resides on an asp page on the server and is used to download files from the server to the machine...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
9
by: AA | last post by:
Hello, I need to extract an element from a xml document something like this <myXml> <Header> <Name/> <LastName/> <Age/> </Head> <Body> <Properties>
2
by: Chris Belcher | last post by:
First some background... The database tracks Action Items assigned to a group of 20 or so managers. Once the assignment is created it is then emailed to each of the managers that are included in...
4
by: Susanne Christe | last post by:
Hi all, I know how to use System.Globalization.RegionInfo, but I have problems to get the Numeric Country Code like this here: http://www.atmajaya.ac.id/Weblinks/KodeNegara.html ISO-3166. ...
2
by: bjm | last post by:
I created a self extracting zip file with about 9000 files in it. I extracted it manually from the command line without a problem. However, when I tried to do the same extraction at the same...
6
by: Mag Gam | last post by:
Hi All, I am new to XML, and trying to extract some data from a file. The file looks like this: <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST>...
6
by: Werner | last post by:
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. False Is there a wrapper or has...
1
by: Edsel | last post by:
Hi all, Can anyone help with this? I would like to extract the attributes from a XML node and then transform them back to XML as elements using XSLT? <unsorted> <office...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.