Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  154] [ 5]  / answers: 1 / hits: 30140  / 14 Years ago, fri, july 9, 2010, 12:00:00

How would I go about trimming/stripping the URL down to the page name...



So: http://www.BurtReynoldsMustache.com/whatever/whoever/apage.html



Would become: apage.html



Any ideas?


More From » jquery

 Answers
1

you do not need jquery:



var url = window.location.href;
var page = url.substring(url.lastIndexOf('/') + 1);


Edit: a good point of the possible query string:



// it might be from browser & / anywhere else
var url = window.location.href;
url = url.split('#').pop().split('?').pop();
var page = url.substring(url.lastIndexOf('/') + 1);


ok, if the location object is available, use pathname gives better result as show below, however, a url can be a string or something directly from text field or span/label. So above solution should have its place.


[#96292] Tuesday, July 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kendellc

Total Points: 84
Total Questions: 97
Total Answers: 102

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;