sam140 sam140 - 9 months ago 75
Javascript Question

unable to Save Canvas As An Image in local machine

how to save my canvas as an image with canvas.toDataURL():
here is my code:

var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");


works fine. how can I change the name of downloaded file? it's coming just "download" and without extension. how i can save this canvas as png image in locally .Please guide me

Answer Source
  1. Create an a element.
  2. Set its href attribute to your url.
  3. Set its download attribute to the desired filename.
  4. Dispatch a click event on your element.

Or just see this answer here.