Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get request uri from location.href in javascript?

Tags:

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?

like image 657
wamp Avatar asked Jul 16 '10 08:07

wamp


2 Answers

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

like image 94
Marcel Jackwerth Avatar answered Sep 29 '22 08:09

Marcel Jackwerth


The location object has a pathname property.

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

var path = location.pathname.substring(1); 
like image 21
Felix Kling Avatar answered Sep 29 '22 08:09

Felix Kling