the url is "http://127.0.0.1:8000/maps/map/wwww/'
how to get the last word
thanks
the url is "http://127.0.0.1:8000/maps/map/wwww/'
how to get the last word
thanks
function getWWWW(string){
return 'wwww';
}
(You might need to provide some more information as to what you want happening. Do you want the 3rd directory to be retrieved? Or the last directory? etc. Until you provide me with that, my answer is valid.)
(The above answer was provided when the author gave the URL and asked how to get the 'wwww', and nothing else. Damn grace editing periods.)
var path = location.pathname;
var directories = path.split("/");
var lastDirecotry = directories[(directories.length - 1)];
Haven't tested and might need a little reworking, but you get the idea.
if you are on a page with this url,
var hrefParts = location.href.split('/');
hrefParts[hrefParts.length - 1] == "wwww";
otherwise,
var href = "http://127.0.0.1:8000/maps/map/wwww/";
href.split('/')[href.length - 1] == "wwww" // you get the idea...
var url = "http://127.0.0.1:8000/maps/map/wwww/";
var last = url.replace(/\/$/, "").split('/').splice(-1, 1);
you could use window.location.pathname and split the string.
something like this:
var pathArray = window.location.pathname.split( '/' );
alert(pathArray[pathArray.length-1]);