My objective is to get the "main" domain name of the current page in JS. By "main", I mean that all these domains should return the same result, "domain":
- domain.com
- domain.co.uk
- subdomain.domain.com
- subdomain.domain.co.uk
As you can see, splitting the query at each period and using a fixed index won't work, as the second and third URLs are of the same length, but the main domain is at different indexes.
Does the browser even recognise a part of the domain as the "main" domain? If so, is there a straight forward way to get it with JS? Are there any libraries that can help me with this?