Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: Getting certain url path using window.location

Our url pathname is

www.nicadpower.com/index.com

but we only want to get the pathname after www.nicadpower.com which is

index.com

how can we get index.com using window.location and jquery

like image 801
DoYouWantaWebsite Avatar asked Jun 18 '11 04:06

DoYouWantaWebsite


2 Answers

I think you want

window.location.pathname

This would give you /index.com

To get rid of the leading /, you could simply use substring:

window.location.pathname.substring(1);
like image 160
Ord Avatar answered Oct 13 '22 19:10

Ord


Here is another trick that you can use. You can split the pathname parts using split method, like that:

If you have the url: www.nicadpower.com/posts/2012

Using: window.location.pathname.split('/')

You'll Give: ["", "posts", "2012"]

like image 27
Sergio Azevedo Avatar answered Oct 13 '22 18:10

Sergio Azevedo