Skip to content

Instantly share code, notes, and snippets.

@LiYiBin
Last active December 28, 2017 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LiYiBin/8e88620b384bc004b82d1827f63ef0cd to your computer and use it in GitHub Desktop.
Save LiYiBin/8e88620b384bc004b82d1827f63ef0cd to your computer and use it in GitHub Desktop.
var uri = $0.toDataURL();
function download(dataurl, filename) {
var a = document.createElement('a');
a.href = dataurl;
a.setAttribute('download', filename);
var e = document.createEvent('MouseEvents');
e.initEvent('click', false, true);
a.dispatchEvent(e);
return false;
}
download(uri, "test.jpg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment