I have a page in which i have multiple canvases. I have a function that allows me to save each canvas one at a time. This function looks like this:
<button onclick="download()">Download</button>
<script>
function download() {
var link = document.createElement('a');
link.download = "pass.jpg";
link.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
link.click();
}
</script>
This is ok if a have maximum 10 canvases, but if my page has 200 canvases to download it would be a problem to click 200 buttons to download them all. I tried to make a function that would save all the canvases from the page at once but it's not quite working. Here is my code:
<button onclick="download()">Download</button>
<script>
function download() {
var images = document.getElementById("canvas");
var srcList = [];
var i = 0;
setInterval(function() {
if (images.length > i) {
srcList.push(images[i].src);
var link = document.createElement("a");
link.id = i;
link.download = "pass.jpg";
link.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
link.click();
i++;
}
}, 1500);
}
</script>
How can i modify this code to get the result i want?