L
L
Ler Den2018-07-19 15:41:43
JavaScript
Ler Den, 2018-07-19 15:41:43

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

3 answer(s)
D
Dmitry Goncharov, 2018-07-19
@givemoneybiatch

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');
});

I
IPv4, 2014-12-01
@IPv4

Bitcoin, probably. Or any cards. Paypal, sort of.

S
Sergey, 2014-12-01
@gangstarcj

Robokassa seems to work with the stores of your plan.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question