By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

How to dynamically chose download file

P: n/a
Need some help.
I would like to create in my site a picture that when a user clicks on
it, a javascript code which determines which file is to be downloaded
to the user, is ran.
My problem is that I do not know how to make the file that was chosen
by the javascript code to be downloaded to the user.
I know how to do it statically (using anchor) what I'm looking for is
how to do it dynamically.

Thanks,

Dec 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Smugsboy wrote:
I would like to create in my site a picture that when a user clicks on
it, a javascript code which determines which file is to be downloaded
to the user, is ran.
My problem is that I do not know how to make the file that was chosen
by the javascript code to be downloaded to the user.
I know how to do it statically (using anchor) what I'm looking for is
how to do it dynamically.


This begs two questions:

1. Why?

2. Are you aware that there is no requirement for a user agent to support
client-side scripting?
PointedEars
Dec 22 '05 #2

P: n/a
Sounds like an interesting idea to me. My solution has always been to
make an anchor to a server side script, and set the output headers to
set the image to download, and send out the image.

If you could do this client-side, you could save an extra request to
the server, as well an extra passing of the image to the client. That
would be very beneficial for a photo gallery in which you allow users
to save copies of the image. (think possible bandwidth reduction for
photo gallery of 50%).

Dec 22 '05 #3

P: n/a

"Smugsboy" <sm*******@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Need some help.
I would like to create in my site a picture that when a user clicks on
it, a javascript code which determines which file is to be downloaded
to the user, is ran.
How is javascript determining the file to be downloaded? What is the logic?
My problem is that I do not know how to make the file that was chosen
by the javascript code to be downloaded to the user.
I know how to do it statically (using anchor) what I'm looking for is
how to do it dynamically.

Dec 22 '05 #4

P: n/a
On 12/22/2005 5:00 PM, Smugsboy wrote:
Need some help.
I would like to create in my site a picture that when a user clicks on
it, a javascript code which determines which file is to be downloaded
to the user, is ran.
My problem is that I do not know how to make the file that was chosen
by the javascript code to be downloaded to the user.
I know how to do it statically (using anchor) what I'm looking for is
how to do it dynamically.


Perhaps this is as simple as

<a href="#" onclick="this.href='/art/somepicture.jpg';">Download</a>

where you can insert Javascript code to determine dynamically which file to
download in place of the explicit choice of '/art/somepicture.jpg'.
Dec 23 '05 #5

P: n/a
Smugsboy said the following on 12/22/2005 5:00 PM:
Need some help.
I would like to create in my site a picture that when a user clicks on
it, a javascript code which determines which file is to be downloaded
to the user, is ran.
My problem is that I do not know how to make the file that was chosen
by the javascript code to be downloaded to the user.
I know how to do it statically (using anchor) what I'm looking for is
how to do it dynamically.


Set the window.location to the URL of the file you want the user to get.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 23 '05 #6

P: n/a
bobzimuta wrote:
Sounds like an interesting idea to me.
/What/ does?

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
<URL:http://www.safalra.com/special/googlegroupsreply/>
My solution has always been to make an anchor to a server side script,
and set the output headers to set the image to download, and send out
the image.

If you could do this client-side,
Do what?
you could save an extra request to the server, as well an extra passing of
the image to the client. That would be very beneficial for a photo gallery
in which you allow users to save copies of the image. (think possible
bandwidth reduction for photo gallery of 50%).


If you quoted what you replied to, you would have seen that there is no
client-side scripting necessary for what the OP really wants. In fact,
a server-side application can easily generate the HTML markup that is
required, without additional requests (the document resource has to be
served either way).
PointedEars
Dec 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.