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"
returns the currentUrl.
If you want to pass your own string as a url (doesn't work in IE11):
Then you can parse it like:
Here is a version that I copied from https://gist.github.com/1847816, but rewritten so it's easier to read and debug. The purpose of copying the of the anchor data to another variable named "result" is because the anchor data is pretty long, and so copying a limited number of values to the result will help simplify the result.
js-uri (available on Google Code) takes a string URL and resolves a URI object from it:
Stop reinventing the wheel. Use https://github.com/medialize/URI.js/
found here: https://gist.github.com/jlong/2428561