Like 1000Bugy's answer , but easier because you donβt need to do the on-the-fly binding and manually send the click event (plus IE fix).
If you make the download button an anchor, you can execute it before the default snap functionality is launched. So, onAnchorClick you can set the href binding to the base64 canvas image and the anchor loading attribute for what you want to call your image.
This does not work in (current) IE, because it does not implement the load attribute and does not allow uris data to be loaded. But this can be fixed using window.navigator.msSaveBlob .
Thus, your anchor event handler will follow (where anchor , canvas and fileName are scopes):
function onClickAnchor(e) { if (window.navigator.msSaveBlob) { window.navigator.msSaveBlob(canvas.msToBlob(), fileName); e.preventDefault(); } else { anchor.setAttribute('download', fileName); anchor.setAttribute('href', canvas.toDataURL()); } }
Here is the violin
Sjeiti Jun 02 '17 at 8:10 2017-06-02 08:10
source share