jquery - Get filename from URL using JavaScript -


i have script grabs filename url have problem.

firstly, here's i've got far:

var img = $('img').attr('src'), filename_index = img.lastindexof("/") + 1,     filename = img.substr(filename_index); 

if url have ?format=foo after filename, part added. there way remove last part starting question mark leaving filename?

try adding line end of code sample:

filename = filename.replace(/[\#\?].*$/,''); // strips hashes, 

string.replace on mdn


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -