For example I\'ve got the simple code:
Though you don't have them in this case, in general you would want to strip off the ?search
and #hash
parts before looking for the last slash to get the file's leafname.
This is very easy using the built-in properties of the link object like pathname
instead of processing the complete href
:
var a= document.getElementById('link1'); // or however you decide to reference it
var filename= a.pathname.split('/').pop(); // get last segment of path