0

I have a canvas drawing that I want to save and download automatically when a button is clicked. I will like to implement it in javascript or ajax as long as the saved data will be downloaded automatically. I do not need to save it to the server...

  var canvas = document.getElementsByClassName('whiteboard')[0];

<canvas id='canvas' ></canvas>
<button id="scan" />Save</button>

Thanks

briandenny
  • 117
  • 1
  • 2
  • 10

1 Answers1

2

I am guessing that you don't need to save at all, just to download your drawing on canvas as image when button is clicked?

There are some good articles on that subject, but here is practical example of what you are trying to do (if my guess is true): Save canvas as image

So basically you add click event listener on your anchor tag with canvas image data uri as href attribute

link.addEventListener('click', function(ev) {
    link.href = canvas.toDataURL();
    link.download = "mypainting.png";
}, false);
Hidajet Tuzlak
  • 125
  • 1
  • 14