Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created July 26, 2015 12:28
Show Gist options
  • Save JavaScript-Packer/b1efe70808171bc9e3a9 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/b1efe70808171bc9e3a9 to your computer and use it in GitHub Desktop.
Encode HTML entities for every character in a string - Demo on http://jsfiddle.net/mjytsf60/
<textarea id=loader rows=11 cols=77></textarea>
<script>
function encodeHTMLentities(w){return w.replace(/[^]/g,function(w){return '&#'+w.charCodeAt(0)+';'})}
loader.value=encodeHTMLentities(document.body.innerHTML)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment