escape.html:
<!DOCTYPE html> <html><head><title>Escape HTML Text</title></head><body><form> <div>text = <br> <textarea id="text" rows="10" cols="80"></textarea></div> <div><button type="button" onclick="setText(escapeHtml(getText()))">text = escapeHtml(text)</button></div> <div><button type="button" onclick="setText(unescapeHtml(getText()))">text = unescapeHtml(text)</button></div> <script type="text/javascript"> //<![CDATA[ function getText() { return document.getElementById("text").value; } function setText(text) { document.getElementById("text").value = text; } function escapeHtml(text) { return text.replace(/&/g,"&").replace(/"/g,""") .replace(/</g,"<").replace(/>/g,">"); } function unescapeHtml(text) { return text.replace(/</g,"<").replace(/>/g,">") .replace(/"/g,"\"").replace(/&/g,"&"); } //]]> </script> </form></body></html>
No comments:
Post a Comment