Skip to content

Instantly share code, notes, and snippets.

@chauek
Last active January 23, 2018 14:49
Show Gist options
  • Save chauek/45daed428a166e2d4db373eaa8622114 to your computer and use it in GitHub Desktop.
Save chauek/45daed428a166e2d4db373eaa8622114 to your computer and use it in GitHub Desktop.
function saveAs(uri, filename) {
var link = document.createElement('a');
if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;
//Firefox requires the link to be in the body
document.body.appendChild(link);
//simulate click
link.click();
//remove the link when done
document.body.removeChild(link);
} else {
window.open(uri);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment