Created
January 14, 2018 13:57
-
-
Save naveed-ahmad/3785cc0e6798452b0ec3828dd562af0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
download= function() { | |
canvas=document.getElementById('canvas') | |
canvas.toBlob(function(blob) { | |
var anchor = document.createElement('a'), | |
dataUrl = URL.createObjectURL(blob), | |
fileName = 'canvas.png'; | |
// set a attributes | |
anchor.setAttribute('href', dataUrl); | |
anchor.setAttribute('target', '_blank'); | |
anchor.setAttribute('download', fileName); | |
// simulate click | |
if (document.createEvent) { | |
evtObj = document.createEvent('MouseEvents'); | |
evtObj.initEvent('click', true, true); | |
anchor.dispatchEvent(evtObj); | |
} | |
else if (anchor.click) { | |
anchor.click(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download Text file using