Skip to content

Instantly share code, notes, and snippets.

@toots
Created March 11, 2013 21:10
Show Gist options
  • Save toots/5137788 to your computer and use it in GitHub Desktop.
Save toots/5137788 to your computer and use it in GitHub Desktop.
Node-webkit: pop out a "save as" dialog with a given default name to save the given data.
saveAs: (name, data) ->
blob = new Blob [data]
url = URL.createObjectURL blob
# HTML5, jQuery, WebKit.. you all SUCK!
# (feels better now!)
$("<a>").attr(href: url, download: name).get()[0].click()
@cmorss
Copy link

cmorss commented Mar 11, 2013

Romain: is this odd because the element is not actually attached to the DOM when you're doing the click? I wonder if you stuck it in the dom you wouldn't need the odd .get()[0] pain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment