Answer the question
In order to leave comments, you need to log in
How to implement image download?
The point is this. By clicking on the button, the user receives a screenshot of a certain area of the site page as a downloaded file. The screenshot is generated at the moment of pressing the button. There is a wonderful library that allows you to turn the DOM into a canvas.
And so I do:
1. Clicking on the button initializes the script, which:
2. Turns the DOM into a canvas
3. We need to programmatically start downloading the file on the client.
It is not clear how step number 3 is done. Is there an event in js?
Answer the question
In order to leave comments, you need to log in
Such an option?
function saveUrlAsFile(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');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question