04 April 2012

I put together a quick little HTML Encoder for myself using JavaScript. I find I am frequently searching for an online encoder when I am writing my posts. The code is below and I find it entertaining that it was encoded for display using the code itself:).

html-encode
  
<script>
  function encode() {
    var theHTML = document.getElementById('rawArea').value;
    theHTML= theHTML
            .replace(/&/g, '&')
            .replace(/"/g, '"')
            .replace(/'/g, ''')
            .replace(/</g, '<')
            .replace(/>/g, '>');
    document.getElementById('encodedArea').value=theHTML;
  }
</script>


<form id="rawForm">
   <textarea id="rawArea" rows="5" cols="40"></textarea>
   <input value="Encode" type="button" onclick="encode(); return false;"/>
</form>

<form id="encodedForm">
   <textarea id="encodedArea" rows="5" cols="40"></textarea>
</form>
  

Less Is More ~ Older posts are available in the archive.