Skip to content

Instantly share code, notes, and snippets.

@THEozmic
Created February 19, 2018 13:33
Show Gist options
  • Save THEozmic/b623124b42ca3516b99f3223d28fae59 to your computer and use it in GitHub Desktop.
Save THEozmic/b623124b42ca3516b99f3223d28fae59 to your computer and use it in GitHub Desktop.
const mimeType = 'text/plain';
const filename = JSON.parse(localStorage.getItem('pads'))[JSON.parse(localStorage.getItem('selected_pad')).id].content.substring(0,8)
const elId = "typing"
const elHtml = document.getElementById(elId).innerHTML;
if (navigator.msSaveBlob) {
navigator.msSaveBlob(new Blob([elHtml], { type: mimeType + ';charset=utf-8;' }), filename);
} else {
const link = document.createElement('a');
link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment