/ Published in: JavaScript
Strips the filename from a url, returns null if one is not found
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
utils.getFilenameFromUrl = function(url) { var charPosition = url.length; var positionFirstSlash; var currentCharacter = url.charAt(charPosition); var breakCharacter = '/'; var filename; if (currentCharacter != breakCharacter) { while(currentCharacter != breakCharacter) { currentCharacter = url.charAt(charPosition); positionFirstSlash = charPosition; charPosition--; } filename = url.substr(positionFirstSlash + 1, url.length); } return filename; }