Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image download 1

Status
Not open for further replies.

hermit22

Programmer
Jul 25, 2001
11
US
A client needs me to allow users to download an image by clicking on it - he doesn't want them to have to right click and go to save as. Is there a way to do this in javascript?
 
Try somethin like this:
<a href=&quot;imageone.gif&quot;>click here to download</a><br>

You don't really need JS, you can achieve this via simple HTML code as well...
I have not failed; I merely found 100,000 different ways of not succeding...
 
That's another part of what I want to avoid. It brings up the image in the browser; the client wants the suer to save it without knowing how. Not sure if I'm making any sense here...
 
OK, now you lost me. What do you mean by: the client wants the suer to save it without knowing how.
The client wants the image to be saved without the user's permission?? I have not failed; I merely found 100,000 different ways of not succeding...
 
Hi all,

Hermit22, if I get this right, you'd like to enable that if the user clicks on a link, the download dialog appears asking to download an image.

If so, the answer is no (sadly). Basically, this is the same problem as with plugins. Each time the user clicks a file, the browser will try to use the right plugin to display the file. If it knows no suitable plugin, it will ask a download.
In case of an image, it is shown in the browser itself, like you said.

The only way to avoid this is to use a zip, or ask the user to 'save target as'.

Gtz,

Kristof
 
I've never tried this, but couldn't you capture a left mouse click on the image and cause it to invoke &quot;save image as&quot;? Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
That's exactly what I'd like to do. At that point, though, I'd have to figure out how to do it for both browsers.
 
Hi all,

Tracy, it would be great if you're idea would work, but alas, I've been thinking the same thing for quite a while but have never encountered a solution.

Possibly, it could be done with a server script by forcing an FTP to a location specified by the user, using his IP address to access his computer. But then ofcourse, the user would have to save it to a directory which is accessable with FTP. (This is just an idea, don't know if i'm actually making sense here :) )

Don't think it can be done with JavaScript (or any other client script).

Gtz,

Kristof
 
comon guyz, go on, i'm curious.. :cool:
Tracy, do u have an idea on how 2 invoke smth like &quot;save as&quot; or is it just an idea? regards, vic
 
It seems to me that I've seen how to invoke the &quot;save as&quot; dialog box on the MS site, but that means it probably doesn't work in NN. Sorry I can't be a lot more accurate. I'm one of those people who can remember that they saw something somewhere, so I can go back and look for it again if I ever need it, but I can't keep all the details in memory (I guess I need a ram upgrade). If the IE only solution is OK, I'll see if I can find it again. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
hermit22,

if i understand this correctly, you want the user to click an image and have it save?

well, if im on the right path here, they already have the file...you just need to move it. Both NN and IE have preset folders on the users machine that hold the temp files...and they are typically not moved much...you may need a little checker to be sure where they are. Once you have that, all you need to do is manipulate thier filing system...

try this tutorial...it's way too long for a post:


hope it helps ;) ~ jsLove ;)
 
hie
thunx jsLove, pretty interesting

Tracy, if u wuld have some time, culd u plz seek for me? i mean this feature u're described..
i'll try 2 find it myself, but just in case if i wont find it..

many thanks regards, vic
 
It took me forever to find again what I had found before, but I finally found it. Unfortunately, it seems only to be able to invoke the &quot;Save Web Page&quot; or &quot;Save HTML Document&quot; dialog, not the &quot;Save Picture As&quot; dialog. Still, if you want to take a look, here's the url:

Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks everyone. I ended up just making self-extractable .exe's for each image; client wanted it too quickly.

I did find this though...
(I don't remember where I found it, I just used net snippets, and went back to it....net snippets is my friend)
Code:
IE supports
  document.execCommand('SaveAs')
to save the current page. It looks as if you can also open a page with 
an image in it and then call the command on the image page:

  function saveImageAs (imgOrURL) {
    if (typeof imgOrURL == 'object')
      imgOrURL = imgOrURL.src;
    window.win = open (imgOrURL);
    setTimeout('win.document.execCommand(&quot;SaveAs&quot;)', 500);
  }
  <A HREF=&quot;javascript: void 0&quot;
     ONCLICK=&quot;saveImageAs(document.anImage); return false&quot;
  >save image</A>
  <IMG NAME=&quot;anImage&quot; SRC=&quot;whatever.gif&quot;>

Note that the img needs to be on the same server as the script.

Of course, it only works in ie.
 
That piece of code could come in handy. I wondered if the SaveAs would work on a page that contained nothing but an image, but didn't get around to trying it out. You just saved me the trouble!
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top