title: Use Javascript to click and trigger downloading of a dynamically generated image
body: <p>I am doing a web application that generates a QR image (PNG format) for a URL. If the URL changes, the image changes too. Here is the HTML (size parameter indicates the size of the QR image):</p>
  <pre><code>&lt;div class=&quot;image&quot;&gt;
      &lt;img src=&quot;/img?size=150&quot; /&gt;             
      &lt;a href=&quot;#&quot;&gt;download&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  <p>My goal is to the image is downloaded (instead of being rendered by the browser) when a visitor clicks on the download link. How can I do this?</p>
  <p>I searched SO and found related posts that use Javascript to download static image. Any difference here?</p>
  <h2>Update</h2>
  <p>I found out this SO link works for me.</p>
  <p><a href="https://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery">Download File Using Javascript/jQuery</a></p>
  <p>Actually there is difference the image is dynamically generated or static. Besides, it guarantees the download for any file types regardless of browser settings.</p>