How to dynamically chose download file

S

Smugsboy

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,
 
T

Thomas 'PointedEars' Lahn

Smugsboy said:
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
 
B

bobzimuta

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%).
 
S

Sean Berry

Smugsboy said:
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?
 
B

Bob Smith

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'.
 
R

Randy Webb

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.
 
T

Thomas 'PointedEars' Lahn

bobzimuta said:
Sounds like an interesting idea to me.

/What/ does?

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top