title: Force browser to download image files on click
body: <p>I need the browser to download the image files just as it does while clicking on an Excel sheet.</p>
  
  <p>Is there a way to do this using client-side programming only?</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;script type="text/javascript" src="Scripts/jquery-1.10.2.js"&gt;
          $(document).ready(function () {
              $("*").click(function () {
                  $("p").hide();
              });
          });
          &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;script type="text/javascript"&gt;
          document.onclick = function (e) {
              e = e || window.event;
              var element = e.target || e.srcElement;
              if (element.innerHTML == "Image") {
                  //someFunction(element.href);
                  var name = element.nameProp;
                  var address = element.href;
                  saveImageAs1(element.nameProp, element.href);
                  return false; // Prevent default action and stop event propagation
              }
              else
                  return true;
          };
  
          function saveImageAs1(name, adress) {
              if (confirm('you wanna save this image?')) {
                  window.win = open(adress);
                  //response.redirect("~/testpage.html");
                  setTimeout('win.document.execCommand("SaveAs")', 100);
                  setTimeout('win.close()', 500);
              }
          }
      &lt;/script&gt;
  
      &lt;body&gt;
          &lt;form id="form1" runat="server"&gt;
              &lt;div&gt;
                  &lt;p&gt;
                      &lt;a href="http://localhost:55298/SaveImage/demo/Sample2.xlsx" target="_blank"&gt;Excel&lt;/a&gt;&lt;br /&gt;
                      &lt;a href="http://localhost:55298/SaveImage/demo/abc.jpg" id="abc"&gt;Image&lt;/a&gt;
                  &lt;/p&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>How should it work in case of downloading an Excel sheet (what browsers do)?</p>