470,618 Members | 1,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,618 developers. It's quick & easy.

Image name only

Hi,

Is there any way that I could get the image name only from
document.getElementById('Image1').src without using any character function
to filter the returned string?
This returns "http://localhost/mywebsite/sampleimage.jpg" but I only need
to get "sampleimage.jpg".

Thanks for your time
Kind regards

Mehdi
Jul 23 '05 #1
2 1071

"Mehdi" <no****@nospam.nospam> wrote in message
news:CE*********************@news-text.cableinet.net...
Hi,

Is there any way that I could get the image name only from
document.getElementById('Image1').src without using any character function
to filter the returned string?
This returns "http://localhost/mywebsite/sampleimage.jpg" but I only need
to get "sampleimage.jpg".

Thanks for your time
Kind regards

Mehdi


Internet Explorer 6 has an additional property on IMG called nameProp which
will do what you want. But if you want to support other browsers try:

var src = document.getElementById('Image1').src;
var fileName = src.substring(src.lastIndexOf('/') + 1);
Jul 23 '05 #2
Thanks Murray, you solved my problem.
Regards
Mehdi
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dave | last post: by
4 posts views Thread by tshad | last post: by
4 posts views Thread by yatin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.