Skip to content

Instantly share code, notes, and snippets.

@toruta39
Last active December 31, 2015 14:39
Show Gist options
  • Save toruta39/8001774 to your computer and use it in GitHub Desktop.
Save toruta39/8001774 to your computer and use it in GitHub Desktop.
Create and download a blob in JS. Tested on the latest Chrome stable
var output = {someKey: "someValue"};
var blob = new Blob([JSON.stringify(output)], {type: 'application/json'});
var anchor = document.createElement('a');
anchor.setAttribute('href', window.URL.createObjectURL(blob));
anchor.setAttribute('download', 'data' + Date.now() + '.json');
anchor.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment