473,799 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4062
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=loc ation.host.repl ace(/^.*\./,"");

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=loc ation.host.repl ace(/^.*\./,"");

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
2540
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 accessing the abobe mentioned asp page. It WORKS for every type of file when I change the content type according to the file type, but it won't work with self extracting files. When an end user downloads a self extracting file by accessing the...
5
2957
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, I have used individual entry fields for each variable. I would now like to use text area boxes to simplify the data entry (this way, data can be produced by another program--FORTRAN, "C", etc.--but analyzed online, so long as it is first...
9
4350
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
2639
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 the scope of the assignment. Among the functions that it provides is the ability to embed the source documents in the database using OLE. The user has requested the ability to forward the source document with the email. The embedded documents...
4
9491
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. Do somebody know how to get them in C#.
2
2211
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 location with the same arguments (using the Process class), a command prompt opens, and it begins extracting files. After about 70 files have been extracted, the main form for my application loses focus and I get an hourglass cursor (which is normal,...
6
6317
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> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY>
6
4457
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 some one experience with other libaries to
1
1893
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 title="Lowe Worldwide" ceo="Stephen" address ="23 Sloane Avenue" city="London" country="USA" postcode="SW3 3PP" tel="0208 999 9999" homepage="http://www.testing.com" logoCol= "10" /> </unsorted> to
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10219
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.