Created
January 29, 2015 14:57
-
-
Save flangofas/724ed26c0e0f6bd18c7f to your computer and use it in GitHub Desktop.
Get last segment from URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get last segment from URL | |
* @note array.filter browser support: IE.9+, Firefox 1.5 + | |
* @return string URL last segment | |
*/ | |
function getLastSegmentFromUrl() { | |
path = window.location.pathname; | |
segments = path.split('/'); | |
//remove empty spaces | |
segments = segments.filter(function(item) { | |
if (item == "") { | |
return false; | |
} | |
return true; | |
}); | |
if (segments.length !== 0) { | |
return segments[segments.length - 1]; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment