tags:

views:

45

answers:

1

hi guys, i have like

http://www.mydomain.com/hello/you

with top.location.host, i can get "http://www.mydomain.com"

with window.location.href i can get "http://www.mydomain.com/hello/you"

is there a chance to get just "/hello/you" ???

+6  A: 
location.pathname

pathname will only return the path. If you want the querystring and optionally hash, you would need to combine the search and hash properties as well. Consider this url:

http://www.example.com/path/to/glory?key=value&world=cup#part/of/page

location.pathname => "/path/to/glory"
location.search   => "?key=value&world=cup"
location.hash     => "#part/of/page"

If you want the entire thing,

/path/to/glory?key=value&world=cup#part/of/page

then just concatenate all these:

location.pathname + location.search + location.hash

Always wanted to use with somewhere. This looks like the perfect opportunity :)

with(location) {
    pathname + search + hash;
}
Anurag
Don't forget `search` and `hash`.
Matthew Flaschen
@Matthew - the querystring or the hash wasn't listed in OP's question, so I can't assume that he will want it, but what I can do is elaborate on my answer :)
Anurag