views:

48

answers:

2

My Javascript ain't so hot, so before I get into some messy string operations, I thought I'd ask:

If the current url is: "http://stackoverflow.com/questions/ask"

What's a good way to to just get: "/questions/ask" ?

Basically I want a string that matches the Url without the domain or the "http://"

+4  A: 
alert(window.location.pathname);

Here's some documentation for you for window.location.

patrick dw
Great, thanks! Works!
Kenji Crosland
@Kenji - You're welcome. :o)
patrick dw
It's not clear whether you want it, but if you potentially want `?query` and `#fragment` parts included (ie *everything* after the domain name) then add on `location.search` and `location.hash`.
bobince
@bobince - +1 Worthwhile addition. Thanks. :o)
patrick dw
+3  A: 

Use window.location.pathname.

xmarcos
Thanks xmarcos!
Kenji Crosland