title: Download image using javascript
body: <p>I would like to know how to download image using javascript.
  It downloads but shows failed error,</p>
  
  <pre><code>&lt;div&gt;
  &lt;button onClick=this.downloadImage(event, "http://example.net/media/image.png")&gt;Download&lt;/button&gt;
  &lt;/div&gt;  
  
  
  
    downloadImage = (event, image) =&gt; {
        var link = document.createElement('a');
        link.href = image.toDataUrl("image/png", 1.0);
        link.download = 'Download.png';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }
  
  
  </code></pre>