Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
197
rated 0 times [  200] [ 3]  / answers: 1 / hits: 30591  / 15 Years ago, wed, august 5, 2009, 12:00:00

I already have quite a bit of js on my site, so I want to have a function that grabs the domain name of the current url as efficiently as possible.



Example:



input : https://stackoverflow.com/questions/ask



result : stackoverflow.com



input : http://test.stackoverflow.com/questions/ask



result : test.stackoverflow.com



I guess the best way to start is with document.location, but I'm at odds what to do from there.


More From » javascript

 Answers
22

Try document.location.hostname


[#98983] Monday, August 3, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hayleevalenciac

Total Points: 164
Total Questions: 89
Total Answers: 106

Location: Burkina Faso
Member since Thu, Dec 15, 2022
2 Years ago
;