I want to get the top domain from strings such as:
domain.com -> domain.com
subdomain.domain.com -> domain.com
subdomain.domain.co.uk -> domain.co.uk
Have the following function so far:
function gdn(h) {
return h.substring(h.lastIndexOf(".", h.lastIndexOf(".") - 1) + 1);
}
Problem is that this does not work with co.uk
domains. The return for:
hello.domain.co.uk -> co.uk
Want it to be domain.co.uk
Any ideas?