title: Open "Save As" Dialog Box To Download Image
body: <p>I've been checking all over the place for an answer to this one but no luck.</p>
  
  <p>I want a button or link that will open the "Save As" dialog box. Simple?</p>
  
  <p>I know I can open the image in a new window/tab (as I'm doing now) and then use the <code>right-click, save as</code> method but as the people using this are not the sharpest knives in the box, so I want to make the download as simple as possible.</p>
  
  <p>The code at the moment is:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;button class="downloadButton" type="submit" onClick="window.open('&lt;%=(rsContent.Fields.Item("ContentImage").Value)%&gt;')"&gt;Download Image&lt;/button&gt;
  </code></pre>
  
  <p>but this loads the image into a new window/new tab.</p>
  
  <p>Just for the record, the users are using Windows XP with Internet Explorer 8 so we can't use the <code>download</code> HTML5 event.</p>
  
  <p>I don't mind if its JavaScript, JQuery or classic ASP.</p>
  
  <p>Thanks in advance for the help.</p>
  
  <p>Pb</p>
  
  <p><strong><em>UPDATE</em></strong></p>
  
  <p>Using the MDN code <a href="https://stackoverflow.com/users/692942/lankymart">Lankymart</a> posted, I tried as-is and it worked (for the open/download of an Excel document), however, I tried changing parts to download images and it didn't work.</p>
  
  <p>Here is the Classic ASP code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>&lt;%
  Dim rsImage__imageID
  rsImage__imageID = "1"
  If (Request.QueryString("imageID")  &lt;&gt; "") Then 
    rsImage__imageID = Request.QueryString("imageID") 
  End If
  %&gt;
  &lt;%
  Dim rsImage
  Dim rsImage_cmd
  Dim rsImage_numRows
  
  Set rsImage_cmd = Server.CreateObject ("ADODB.Command")
  rsImage_cmd.ActiveConnection = MM_ENG_STRING
  rsImage_cmd.CommandText = "SELECT ContentID, ContentImage, DisplayImage FROM tblContent WHERE ContentImage = ?" 
  rsImage_cmd.Prepared = true
  rsImage_cmd.Parameters.Append rsImage_cmd.CreateParameter("param1", 5, 1, -1, rsImage__imageID) ' adDouble
  
  Set rsImage = rsImage_cmd.Execute
  rsImage_numRows = 0
  %&gt;
  </code></pre>
  
  <p>and the (badly) altered MDN code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>&lt;%
  'Set the content type to the specific type that you are sending.
  Response.ContentType = "image/JPEG"
  
  Const adTypeBinary = 1
  Dim strImageFile
  
  strImageFile = (rsImage.Fields.Item("ContentImage").Value) 'This is the path and name of the file on disk. 
  
  Set objStream = Server.CreateObject("ADODB.Stream")
  objStream.Open
  objStream.Type = adTypeBinary
  objStream.LoadFromFile strImageFile
  
  Response.BinaryWrite objStream.Read
  
  objStream.Close
  Set objStream = Nothing
  %&gt;
  </code></pre>
  
  <p>I call it using:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;button class="downloadButton" type="submit" onClick="window.location.href='image-download.asp?imageID=&lt;%=(rsContent.Fields.Item("ContentID").Value)%&gt;';"&gt;Download Image&lt;/button&gt;
  </code></pre>
  
  <p>The error it produces is:</p>
  
  <pre class="lang-none prettyprint-override"><code>The image “http://localhost:85/admin/english/image-download.…p?imageID=5” cannot be displayed because it contains errors.
  </code></pre>
  
  <p>The page code is:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;html&gt;
  
      &lt;head&gt;
          &lt;meta name="viewport" content="width=device-width; height=device-height;"&gt;&lt;/meta&gt;
          &lt;link rel="stylesheet" href="resource://gre/res/ImageDocument.css"&gt;&lt;/link&gt;
          &lt;link rel="stylesheet" href="resource://gre/res/TopLevelImageDocument.css"&gt;&lt;/link&gt;
          &lt;link rel="stylesheet" href="chrome://global/skin/media/TopLevelImageDocument.css"&gt;&lt;/link&gt;
          &lt;title&gt;
  
              image-download.asp (JPEG Image)
  
          &lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;img src="http://localhost:85/admin/english/image-download.asp?imageID=5" alt="The image “http://localhost:85/admin/english/image-download.…p?imageID=5” cannot be displayed because it contains errors." title=""&gt;&lt;/img&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>