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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
In a browser
You can leverage the browser’s URL parser using an
<a>element:or without jQuery:
(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:
Use it like this:
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.