Skip to content

Instantly share code, notes, and snippets.

@afandiyusuf
Created May 5, 2020 04:53
Show Gist options
  • Save afandiyusuf/12468986110ec4d8d41ca528ee5ee768 to your computer and use it in GitHub Desktop.
Save afandiyusuf/12468986110ec4d8d41ca528ee5ee768 to your computer and use it in GitHub Desktop.
Download file from javascript
let a = document.createElement('a');
a.href = "data:application/octet-stream,"+encodeURIComponent([url_image_or_document]);
a.download = 'myFile.json';//filename
a.click();
//source
//https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment