/    Sign up×
Community /Pin to ProfileBookmark

Is there any way to get the image name by use of javascript?

Hi, I am new!
I use this html to get a image from the webserver:
<img src=”mypic.php?uid=5555″ … >
I have named the imagefile with ‘abcd.gif’ via writing it in the http response header.
But can I get it(‘abcd.gif’) by use of javascript and how to?
Thanks in advance!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienFeb 05.2009 — You could add the image name to the query string in the src attribute:
[CODE]<img src="mypic.php?uid=5555[B]&filename=abcd.gif[/B]" [B]id="myImage"[/B] ... />[/CODE]
Then search the web for a JavaScript function that reads query strings.
[CODE]var img = document.getElementById("myImage");
var imgName = /* pass img.src to a function that reads a query string, extract filename */;[/CODE]

Also, for XHTML, the slash before the ">" character on an <img> tag should be a forward slash, not a back slash.
Copy linkTweet thisAlerts:
@eingmarraauthorFeb 06.2009 — hi, toicontien:

I am very thankful for your suggestion!

But I cant add this param--'filename=abcd' in the request url... because the image name abcd is generated by serverside(it depend on the image which is fetched back). For example, if the request is legal, the back image name is 'abcd', and if not the image name is 'error'.

I am really stucked here!

Help me!
Copy linkTweet thisAlerts:
@toicontienFeb 06.2009 — Can you edit the server side script? Because if you can't, there's no way you can access the image name.

On the other hand, maybe you could make an AJAX request for that image, and then you can read the HTTP headers.
Copy linkTweet thisAlerts:
@eingmarraauthorFeb 09.2009 — Thank you toicontien!

'On the other hand, maybe you could make an AJAX request for that image, and then you can read the HTTP headers. ' --- I think what you said is the only way for my need! I will do it like you said!
×

Success!

Help @eingmarra spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...