Figuring out Host's Top Domain with Javascript
- by timeitquery
Is there a way to figure out what the top domain for the hostname of the current page is? The problem I have is that the script could be on .com domain, or in an international domain like .co.uk
So for:
jobs.telegraph.co.uk - top domain is:telegraph.co.uk
jobs.nytimes.com - top domain is nytimes.com
The problem is that location.hostname , and the document.domain give the entire domain.
One route is to have a list of all TLDs (too much to carry around) and parse based on that. Another route was if 2 characters after last ".", than internationaltion - hence last two are the TLD, but that does not hold true for all international domains.