Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3806714
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:52:39+00:00 2026-05-19T14:52:39+00:00

I have domain name for eq. 1) http://www.abc.com/search 2) http://go.abc.com/work I get only domain

  • 0

I have domain name for eq.

1) http://www.abc.com/search 
2) http://go.abc.com/work

I get only domain name from the above URL

Output like

1) http://www.abc.com/
2) http://go.abc.com/

how can I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:52:40+00:00Added an answer on May 19, 2026 at 2:52 pm

    In a browser

    You can leverage the browser’s URL parser using an <a> element:

    var hostname = $('<a>').prop('href', url).prop('hostname');
    

    or without jQuery:

    var a = document.createElement('a');
    a.href = url;
    var hostname = a.hostname;
    

    (This trick is particularly useful for resolving paths relative to the current page.)

    Outside of a browser (and probably more efficiently):

    Use the following function:

    function get_hostname(url) {
        var m = url.match(/^http:\/\/[^/]+/);
        return m ? m[0] : null;
    }
    

    Use it like this:

    get_hostname("http://example.com/path");
    

    This will return http://example.com/ as in your example output.

    Hostname of the current page

    If you are only trying the get the hostname of the current page, use document.location.hostname.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a domain name abc.mydomain.com This is a https URL ( http redirects
I have this code right here: // get host name from URL preg_match('@^(?:http://)?([^/]+)@i', http://www.joomla.subdomain.php.net/index.html,
Imagine that I have url http://www.google.com/subdomain/blah-blah.../.. /.. So I want to extract 4 things
I wish to canonicalize a domain name, from bar.example.com to www.example.com (well anything that's
I have a string like this: http://www.downlinegoldmine.com/viralmarketing I need to remove http://www. from the
I have installed teampulse http://www.telerik.com/team-productivity-tools.aspx community. I add in bindings my domain name with
I have obtained hosting space and they registered domain(say www.abc.com ) with an ip(say
If I have domain name example.com , and if I set an A record
I have a domain name: TestSite.com. I create several subdomains for this site and
I need a php function which produce a pure domain name from URL. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.