var parts = location.hostname.split('.');
var subdomain = parts.shift();
var upperleveldomain = parts.join('.');
To get only the second-level-domain, you might use
var parts = location.hostname.split('.');
var sndleveldomain = parts.slice(-2).join('.');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…