tags:

views:

32

answers:

3

What I get from location.href is like this:

http://stackoverflow.com/questions/ask

But I only want to get questions/ask (no / at the first character)

How to achieve this?

+2  A: 

window.location.pathname.substr(1) would that be.

Marcel J.
Why both `substr` and `substring` works ?
wamp
A: 

You can use location.pathname.substring(1)

Gunjan
A: 

The location object has a pathname property.

This will give you /questions/ask and to remove the first character, use substring(1):

var path = window.location.pathname.substring(1);
Felix Kling
Which is better ,`substr` or `substring`?
wamp
@wamp: There is no *better* (what do you mean with that anyway?). They work differently. `substr` takes a length as second parameter, and `substring` another index (up to which the string should be extracted). In this case it does not matter which one you use (and I *assume* that internally it is the same function anyway).
Felix Kling