1

I know I can read the hash value of a URL with javascript/jquery. But is is possible that I can read the trailing bit? Finding the last piece of the URL

I have a domain. http://www.blah.com/ each section of the domain resides under a URL that is slug like "this-page" example

http://www.blah.com/service/ (with or without the trailing slash) But I want to know if I can find "service" in the URL with JavaScript, without Server Side intervention. I know I could do it if I had http://www.blah.com/#service

I don't know Im just curious, I really don't know what I would look for otherwise so this is my first stop in my search cause I am clueless..

2 Answers 2

2
var p = location.pathname;
p = p.substring(p.length-1) == '/' ? p.substring(0, p.length-1) : p;
p.split('/').pop();
Sign up to request clarification or add additional context in comments.

Comments

1

Use regex:

last_bit = $(location).attr('href').replace(/https?:\/\/[^\/]+/i, "");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.