My page’s URL is like this:
http://www.mydomain.com/directory/thisismy_page.html
Using JavaScript, I want to pull out the part of the page’s filename before the underscore. So in this example, I want:
thisismy
I currently have this:
var filename = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
But that pulls out thisismy_page.html. How do I “stop” it at the underscore so all I get is thisismy?
This splits it at the underscore and takes the first (or 0th part).