Figuring out Host's Top Domain with Javascript

Posted by timeitquery on Stack Overflow See other posts from Stack Overflow or by timeitquery
Published on 2010-06-17T13:37:54Z Indexed on 2010/06/17 14:13 UTC
Read the original article Hit count: 190

Filed under:

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.

© Stack Overflow or respective owner

Related posts about JavaScript