How to get a subdomain using window.location?
This does the trick for me:
var host = window.location.host
var subdomain = host.split('.')[0]
Yes, window.location.hostname
will give you subdomains as well. If this isn't working, or isn't supported by some other browser, you could quite easily parse for it:
// window.location.href == "http://sample.somedomain.com/somedir/somepage.html"
var domain = /:\/\/([^\/]+)/.exec(window.location.href)[1];