SyntaxFix
Write A Post
Hire A Developer
Questions
Since this question asks for domain name, not host name, a correct answer should be
window.location.hostname.split('.').slice(-2).join('.')
This works for host names like www.example.com too.