This code will show only the last part of any URL
URL GIVEN : www.codehaven.co.uk/firstpart/secondpart/themainimage.jpg
URL OUTPUT: themainimage.jpg
1 2 3 4 5 6 7 8 9 10 11 |
function multiply(x) { var url = x; var array = url.split('/'); thetext = array[array.length-1]; var thetextshort = thetext.substring(thetext.lastIndexOf("/") + 1, url.length); return thetextshort; } alert(multiply("www.codehaven.co.uk/firstpart/secondpart/themainimage.jpg")); |