Personally, I try to use simple string manipulation for such simple tasks. This makes for more readable code (for a person not very familiar with RegEx).
var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/')+1);
Or simply:
var filename = window.location.pathname.substring(window.location.pathname.lastIndexOf('/')+1);
Additional Information
It doesn't matter if it is so trivial, but this method is also more efficient than RegEx: http://jsperf.com/get-file-name
source share