Javascript Question

How I can create a button for save a image with Javascript or any Javascript framework?

I would like save with a button a generated picture. I see the fastest solution is

JavaScript
, probably
JQuery
or any framework.

My application generate a
img
label, for example:

<img src = "data:image/png;base64,iVBORw0KGgo...(it's very long)"/>


The many problem is the
src
attribute because change for my application, first I need catch the URL of this.

Thank you very much!

Answer

You can use the download attribute in HTML. If the img src is automatically generated, you could use the script below to put it in the href:

$('#save').prop('href', $('img').prop('src'));
<img src="http://blog.grio.com/wp-content/uploads/2012/09/stackoverflow.png"/><br/>
<a id='save' download>Save</a>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>