Advertisement
Guest User

browserpad: save contenteditable as text file (PoC)

a guest
Mar 23rd, 2013
3,477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data:text/html, <html>
  2. <style type="text/css">
  3.   body{overflow:hidden;}
  4.   #iframe{display:none;}
  5.   #div{position:absolute;top:0px;left:0px;width:100%;height:10000px;}
  6.   #saveButton{z-index:2;position:absolute;top:0px;right:0px;}
  7. </style>
  8. <script>
  9. function save(){
  10.   var note = document.getElementById('div').innerHTML;
  11.   note = note.replace(/(<div><br>)*<\/div>/g, '\n');
  12.   note = note.replace(/<div>/g, '');
  13.   /* replaces some html entities */
  14.   note = note.replace(/&nbsp;/g, ' ');
  15.   note = note.replace(/&amp;/g, '&');
  16.   note = note.replace(/&lt;/g, '<');
  17.   note = note.replace(/&gt;/g, '>');
  18.   document.getElementById('saveButton').setAttribute(
  19.     'href',
  20.     'data:Content-type: text/plain, ' + escape(note)
  21.   );
  22. }
  23. </script>
  24. <a id="saveButton" target="iframe" download="note.txt" href="#" onclick="save();">Save</a>
  25. <iframe id="iframe"></iframe>
  26. <div contenteditable id="div"></div>
  27. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement