I would like to take a string
var a = "http://example.com/aa/bb/"
and process it into an object such that
a.hostname == "example.com"
and
a.pathname == "/aa/bb"
I would like to take a string
var a = "http://example.com/aa/bb/"
and process it into an object such that
a.hostname == "example.com"
and
a.pathname == "/aa/bb"
js-uri (available on Google Code) takes a string URL and resolves a URI object from it:
var some_uri = new URI("http://www.example.com/foo/bar");
alert(some_uri.authority); // www.example.com
alert(some_uri); // http://www.example.com/foo/bar
var blah = new URI("blah");
var blah_full = blah.resolve(some_uri);
alert(blah_full); // http://www.example.com/foo/blah
var getLocation = function(href) {
var l = document.createElement("a");
l.href = href;
return l
}
var l = getLocation("http://example.com/path");
console.debug(l.hostname)
>> "example.com"
console.debug(l.pathname)
>> "/path"