faqts : Computers : Programming : Languages : JavaScript : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

124 of 163 people (76%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I call save as on an IMG/Image?

Mar 31st, 2000 03:16
Martin Honnen,


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("SaveAs")', 500);
  }
  <A HREF="javascript: void 0"
     ONCLICK="saveImageAs(document.anImage); return false"
  >save image</A>
  <IMG NAME="anImage" SRC="whatever.gif">

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