How to download pictures?

The bottom line is this. The user by clicking on the button gets a screenshot of a specific area page in the downloaded file. A screenshot is generated at the moment of pressing the button. There is a wonderful librarythat allows you to convert a DOM into canvas.
And so I do:
1. Click the button initialisere a script that:
2. Turns the DOM into canvas
3. Need to programmatically start file downloading on the client.
It is not clear how to do step # 3. There are event some in HPD?
June 3rd 19 at 19:36
1 answer
June 3rd 19 at 19:38
Solution
Such an option?

saveUrlAsFile function(url, fileName) { 
 var link = document.createElement("a"); 
 link.setAttribute("href", url);
 link.setAttribute("download", fileName);
link.click();
}

$('img').on('click',function(e){
 saveUrlAsFile($(e.target).attr('src'), 'image.jpg');
});

Find more questions by tags JavaScriptHTMLNode.jsCanvas