Skip to content

Instantly share code, notes, and snippets.

@benjaminaaron
Created August 24, 2017 19:47
Show Gist options
  • Save benjaminaaron/804de6a58dcfcf722427a7b4f7249df6 to your computer and use it in GitHub Desktop.
Save benjaminaaron/804de6a58dcfcf722427a7b4f7249df6 to your computer and use it in GitHub Desktop.
download the content of a DOM element as text - run in browser console
function saveAsTextFile(element, filename) { // via stackoverflow.com/a/32858416
var textFileAsBlob = new Blob([element.innerHTML], {type:'text/plain'});
var link = document.createElement("a");
link.download = filename;
link.href = window.URL.createObjectURL(textFileAsBlob); // works only in Chrome without attaching it to the DOM
link.click();
}
saveAsTextFile(document.getElementById("content"), "content.xml");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment