Created
March 23, 2013 14:25
-
-
Save usmonster/5227893 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(/ /g, ' '); | |
note = note.replace(/&/g, '&'); | |
note = note.replace(/</g, '<'); | |
note = note.replace(/>/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