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]
- split on '?' throw out query string parameters
- get first of splits
- split on '/'.
- for splits, filter away empty strings
- get last 1 remaining
Comments
Post a Comment