:
window.location.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
This will lead to a change in the location of the browser to a data URL containing PNG of the contents of the canvas, which the browser will offer to save (by changing the forces like mime, otherwise the browser will display only PNG.)
source
share