is there a really easy way to turn document.location.href=="http://aaa.bbb.ccc.ddd.com/asdf/sadf/asdf/asdf/asdf/sadf.aspx?blah" into 'aaa.bbb.ccc.ddd.com'?
There's gotta be a JS function that does this reliably, but I can't find it.
is there a really easy way to turn document.location.href=="http://aaa.bbb.ccc.ddd.com/asdf/sadf/asdf/asdf/asdf/sadf.aspx?blah" into 'aaa.bbb.ccc.ddd.com'?
There's gotta be a JS function that does this reliably, but I can't find it.
You can use
window.location.pathname
Oh, no you can't sorry. This returns the last portion of the URL. Oops.
You could concatenate the location protocol and the host:
var root = location.protocol + '//' + location.host;
For a url, let say 'http://stackoverflow.com/questions'
, it will return 'http://stackoverflow.com'
Use document.location
object and its host
or hostname
properties.
alert(document.location.hostname); // alerts "stackoverflow.com"