Skip to content

Instantly share code, notes, and snippets.

@usmonster
Created March 23, 2013 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usmonster/5227893 to your computer and use it in GitHub Desktop.
Save usmonster/5227893 to your computer and use it in GitHub Desktop.
data:text/html, <html>
<!--
modified from http://pastebin.com/4z8tttuA
answer to http://stackoverflow.com/questions/15582152/turns-browser-into-notepad-but-cant-save-html-contenteditable
-->
<style type="text/css">
body{overflow:hidden;}
#iframe{display:none;}
#div{position:absolute;top:0px;left:0px;width:100%;height:10000px;}
#saveButton{z-index:2;position:absolute;top:0px;right:0px;}
</style>
<script>
function save(){
var note = document.getElementById('div').innerHTML;
note = note.replace(/(<div><br>)*<\/div>/g, '\n');
note = note.replace(/<div>/g, '');
/* replaces some html entities */
note = note.replace(/&nbsp;/g, ' ');
note = note.replace(/&amp;/g, '&');
note = note.replace(/&lt;/g, '<');
note = note.replace(/&gt;/g, '>');
document.getElementById('saveButton').setAttribute(
'href',
'data:Content-type: text/plain, ' + escape(note)
);
}
</script>
<a id="saveButton" target="iframe" download="note.txt" href="#" onclick="save();">Save</a>
<iframe id="iframe"></iframe>
<div contenteditable id="div"></div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment