0

Looking at using HTML2Canvas to save a HTML div, I am looking at saving the div with the id "imagesave" I have seen examples online of the following code working to do this but when I press download image nothing happens, how can I make this work?

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>

<button id="save_image_locally">download img</button>

   <div id="imagesave">
     <p>testing</p>
        <p>testing</p>
   </div>

<script>

  $('#save_image_locally').click(function(){
    html2canvas($('#imagesave'), 
    {
      onrendered: function (canvas) {
        var a = document.createElement('a');
        a.href = canvas.toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream");
        a.download = 'somefilename.jpg';
        a.click();
      }
    });
  });

</script>
</body>
</html>
Curtis Boylan
  • 827
  • 1
  • 7
  • 23

1 Answers1

0

specify background color, add CSS like:

#imagesave {
  background:lightblue;
}
Enirdas
  • 119
  • 8