简体   繁体   中英

How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

I'm struggling to figure this out: When user clicks on button it creates a png of whatever the content is in my "imagecontainer" element. Unfortunately it only adds a canvas with the png to the bottom of my page. How can I prevent it from doing that and let the png get straight into dowloads folder or new window?? Thank you so much. This is my code:

 $(function() { $("#savebutton").click(function() { html2canvas($(".imagecontainer"), { onrendered: function(canvas) { theCanvas = canvas; document.body.appendChild(canvas); canvas.toBlob(function(blob) { save(blob, "Dashboard.png"); }); } }); }); }); 

When you append an element to document.body it's naturally placed in the bottom of the page. Append your canvas to the element you want to contain it. For example to imagecontainer :

$(".imagecontainer").append(canvas);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM