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:).

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

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

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

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