Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rjcorwin/5497275 to your computer and use it in GitHub Desktop.

Select an option

Save rjcorwin/5497275 to your computer and use it in GitHub Desktop.
window.URL = window.URL || window.webkitURL
var blob = new Blob(['body { color: red; }'], {type: 'text/css'})
var link = document.createElement('a')
link.innerHTML = 'Click to download style.css.'
link.href = window.URL.createObjectURL(blob)
// Name the Blob so it doesn't result in a gibberish name
link.download = 'style.css'
// Append the download link to the body
document.body.appendChild(link)
// Optionally, if you want this to immediately download and don't care about the download link, run the click method
// link.click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment