6

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

2 Answers 2

9

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);
Sign up to request clarification or add additional context in comments.

2 Comments

console.log(window.location.pathname.substring(1)); putting this one on my js says that is getting www.nicadpower.com/index.php
thanks ord! now is works good. i just added more integer on the substring. thanks a lot!
2

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"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.