JavaScript get last URL segment -


what best way last segment of url (omitting parameters). url may or may not include last '/' character

for example

http://home/billing/index.html?param1=2&another=2 should result in: index.html  http://home/billing/index.html/ should result in: index.html 

i've tried can't how check last /

ar href = window.location.pathname;             var value = href.lastindexof('/') + 1); 

maybe like?

window.location.pathname.split('?')[0].split('/').filter(function (i) { return !== ""}).slice(-1)[0] 
  1. split on '?' throw out query string parameters
  2. get first of splits
  3. split on '/'.
  4. for splits, filter away empty strings
  5. get last 1 remaining

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -