<script type="text/javascript">
/*
Simple HTML escaper by Raymond May Jr.
Uses global regex to replace < and > with HTML entities.
http://www.compender.com
*/
function escape()
{
var input = document.getElementById("input").value;
input = input.replace(/&/g,"&");
input = input.replace(/</g,"<");
input = input.replace(/>/g,">");
document.getElementById("input").value = input;
}
function unEscape()
{
var input = document.getElementById("input").value;
input = input.replace(/</g,"<");
input = input.replace(/>/g,">");
input = input.replace(/&/g,"&");
document.getElementById("input").value = input;
}
</script>
<html>
<body>
<h2>HTML Escaper</h2>
<form>
<textarea id="input" rows="30" cols="80"></textarea>
<br />
<input type="button" value="Escape!" onClick="escape()" />
<input type="button" value="Un-Escape!" onClick="unEscape()" />
</form>
</body>
</html>
No comments:
Post a Comment