document.getElementById("canvasimg_bk").style.display = "none";
}
function saveCanvas(canvas,ctx) {
- alert('Starting Download');
- //var dataURL = canvas.toDataURL();
- //document.getElementById("canvasimg").src = dataURL;
- //var dt = canvas.toDataURL('image/png');
- //var dt = canvas.toDataURL();
- /* Change MIME type to trick the browser to downlaod the file instead of displaying it */
- //dt = dt.replace(/^data:image\/[^;]*/, 'data:application/octet-stream');
- /* In addition to <a>'s "download" attribute, you can define HTTP-style headers */
- //dt = dt.replace(/^data:application\/octet-stream/, 'data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=Canvas.png');
- //this.href = dt;
- var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // here is the most important part because if you dont replace you will get a DOM 18 exception.
- window.location.href=image; // it will save locally
+ //var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
+ // here is the most important part because if you dont replace you will get a DOM 18 exception.
+ //window.location.href=image; // it will save locally
+ var link = document.getElementById('link');
+ link.setAttribute('download', 'Green-Party-petition.png');
+ link.setAttribute('href', canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"));
+ link.click();
+
}
<input type="submit" value="SAVE to SHARE" id="sharebutton" onclick="saveCanvas(canvas,ctx);">
<input type="submit" value="BACK" id="clearbutton" onclick="clearCanvas(canvas,ctx);">
<input type="submit" value="CLEAR" id="clearbutton" onclick="clearCanvas(canvas,ctx);">
+ <a id="link"></a>
</div>
<div id="sketchpadapp">
<div class="rightside">