Posted By

nate63179 on 11/11/09


Tagged

utils


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


Get filename from url


 / Published in: JavaScript
 

Strips the filename from a url, returns null if one is not found

  1. utils.getFilenameFromUrl = function(url) {
  2. var charPosition = url.length;
  3. var positionFirstSlash;
  4. var currentCharacter = url.charAt(charPosition);
  5. var breakCharacter = '/';
  6. var filename;
  7. if (currentCharacter != breakCharacter) {
  8. while(currentCharacter != breakCharacter) {
  9. currentCharacter = url.charAt(charPosition);
  10. positionFirstSlash = charPosition;
  11. charPosition--;
  12. }
  13. filename = url.substr(positionFirstSlash + 1, url.length);
  14. }
  15. return filename;
  16. }

Report this snippet  

You need to login to post a comment.