473,216 Members | 1,920 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,216 software developers and data experts.

get domain name from url

i need to get the domain name from the url in javascript.

for eg if the url is "http://bytes.com/forum/newthread.php", i need to get bytes.com alone.

any quick help will be appreciated.
Sep 4 '08 #1
5 41708
gits
5,390 Expert Mod 4TB
you may use:

Expand|Select|Wrap|Line Numbers
  1. var hn = window.location.hostname;
Sep 4 '08 #2
Thanks for the quick reply....this returns the domain name of the current url...
i need this to be a utility function where i can pass a url and get the domain name.
Sep 4 '08 #3
gits
5,390 Expert Mod 4TB
hmmm ... that's another question ... try a regExp like the following:

Expand|Select|Wrap|Line Numbers
  1. var url = 'http://bytes.com/forum/newthread.php';
  2.  
  3. function get_hostname_from_url(url) {
  4.     return url.match(/:\/\/(.[^/]+)/)[1];
  5. }
  6.  
  7. alert(get_hostname_from_url(url));
kind regards
Sep 4 '08 #4
k..thanks..i'll try that
Sep 5 '08 #5
rnd me
427 Expert 256MB
looks a little fragile.

try url.split(/\/+/g)[1];
Sep 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jordan | last post by:
Suppose I register a domain name, MyDomain.com, through register.com (or any other of the many domain name registrars). I own the domain name. The domain name goes into the global DNS database. ...
3
by: Bruno | last post by:
Hello Friends I have a big problem. I can't retrieve the domain name (example: contoso.com) using visual basic.net language. I'm very appreciate if anyone give me an example how can I solve...
4
by: Bruno | last post by:
Hello friends I need to create a simple application that returns the domain name where the user name logs in. For example, if I acccess in a computer with the domain user Contoso\bruno, my...
16
by: Michael | last post by:
Does someone have a reliable routine to get the domain name of the current user of a web page? Something like NSLookup. I have no problem getting their IP address, but I also want the domaine...
6
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
6
by: Adam Tibi | last post by:
Hello, I want to get the right most name of the a domain name, for example: if the domain is www.myweb.com , I want to get myweb.com something.myweb.com --> myweb.com www.myweb.com.au --> ...
6
by: Spyder | last post by:
When you go to "MyComputer" and get properties and select "Computer Name", you get the Domain or Workgroup a computer belongs to. I have looked thru MSDN library, the Internet, the Registry and in...
8
by: None | last post by:
Hi, If anybody knows how to get the domain name(only domain name) of the system pls let me know. Thanks and Regards, Vinothkumar B bvinoth@tvsinfotech.com
0
by: tim.mayo | last post by:
I'm trying to write a component in VB.NET that takes a user account and returns the Active Directory domain name of the user account. Since it's not a windows/web application, I can't use...
9
by: Sam | last post by:
Validate domain name context Hello , Today I want to make sure from a given text is a domain style or not. for example : the domain can be example.com or example.com.us or example.us so ,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.