Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

jQuery - get last part of URL

0 votes
2 views
added Mar 30 in jQuery by theoh_lee Lance Corporal (790 points)

When folder hierarchy increases like www.example.com/folder/sub-folder/sub-sub-folder/code/12345

$(function () {
     siteCode = getLastPartOfUrl('www.example.com/folder/code/12345/');
});

var getLastPartOfUrl =function($url) {
    var url = $url;
    var urlsplit = url.split("/");
    var lastpart = urlsplit[urlsplit.length-1];
    if(lastpart==='')
    {
        lastpart = urlsplit[urlsplit.length-2];
    }
    return lastpart;
}

src: https://stackoverflow.com/questions/17166791/jquery-get-last-part-of-url

Please log in or register to example this solution.

lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...