Wednesday, May 9, 2012

JavaScript - Get file name from URL

This function get file name from URL by javascript:

function getFileName()
 {

      var url = document.location.href;

      url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));

      url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));

      url = url.substring(url.lastIndexOf("/") + 1, url.length);

     return url;
}

No comments:

Post a Comment